-2

I have created an instance of my database helper class in the main activity.

I want to access that instance from any another activity where I can update that database. I have created an instance with getApplicationContext() as context but it's still not showing that instance in another activity.

Ashishkumar Singh
  • 3,580
  • 1
  • 23
  • 41

1 Answers1

0

Instead of Main Activity, you can create database on Application file.

Then you can access it from anywhere, not specific activity.

Application App

public class ApplicantApp extends Application{

    private static Database yourdatabasevariable;
} 

Another Activity

public class ActivityA{
   Application.yourdatabasevariable;
}
AFin
  • 61
  • 2