I’m using the activity groups to navigate between several activities under one tab.
However when I get to the first child activity and press back I am getting the following error:
java.lang.NullPointerException at
com.android.TopActivity.onBackPressed(TopActivity.java:208)
at android.app.Activity.onKeyUp(Activity.java:1904)
This is the method it’s crashing on:
@Override
public void onBackPressed()
{
int length = idList.size();
if (length > 1)
{
Activity current = getLocalActivityManager().getActivity(
idList.get(length -1));
//Log.i("CURRENT ACTIVITY =","CURRENT ACTIVITY "+current.getClass().getName());
current.onBackPressed();
}
}
I setup the idList with the following:
idList.add("HomeActivity");
idList.add("TopActivity");
I’m trying to call the onBackPressed method in the TopActivity class but it keeps crashing.
What am I doing wrong? Am I putting the correct values into the idList?
It is hard to tell from your description, but it sounds like you might be better served by implementing your design with Fragments (assuming you are targeting platform versions for which there is an appropriate support library).
That said, what about using
getLocalActivityManager().getCurrentActivity()instead of trying to maintain some type of stack of IDs? It seems that you are probably wanting to send the back press to the “current” activity anyway, right?