I’ve been trying many different ways and getting null pointer exceptions.
Scenario: Activity1 loads on start and calls Activity2 if the num of rows in the table is 0. Now I want it to go back to Activity1 when the number of rows is 0 and that call would coem from the db handler.
In the database handler class:
if(num ==0){
Activity1 bs1 = new Activity1();
Context context = bs1.getApplicationContext();
Intent intent = new Intent();//
intent.setClass(context, Activity1.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);
}
Activity1 onCreate()
int num = db.numOfRows();
if(num==0){
setContentView(R.layout.main);
} else {
startActivity(new Intent(this, Activity2.class));//
}
Activity2 onCreate()
super.onCreate(savedInstanceState);
setContentView(R.layout.moreprojects);
populateRows();
Thanks in advance.
You dont use constructor to call new activity. See below: