0

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()?

Joshua
  • 8,112
  • 3
  • 35
  • 40
Sohel Mansuri
  • 564
  • 2
  • 6
  • 18

1 Answers1

1

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
stinepike
  • 54,068
  • 14
  • 92
  • 112