Question

I have a small issue. I have looked all over the internet but I cannot find a solution to my problem. The problem I have is:

I have a TabHost that has 3 tabs. The first tab opens Activity A. In Activity A, I can press in a listview and it will change the setContent() to Activity B. When I press the back button in Activity B, the onBackPressed() function of Activity A gets called.

How can I close Activity B and go back to Activity A onBackPressed()?

Was it helpful?

Solution

This is how i did it

private void onBackPressed(){
    RootActivity parentActivity;
    parentActivity = (RootActivity) this.getParent();
    parentActivity.switchToSecondActivity();
} // here RootActivity is the tabhost

in RootActivity

public void switchToSecondActivity(){
    tabHost.setCurrentTab(SECOND); 
} //SECOND is an integer pointing location of the second activity. it starts from 0
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top