Switching back to previous activity in tabhost

274 views Asked by At

I am using TabActivity(for example, TActivity) to create tab and in every tab I am loading instance of same activity(for example, MainActivity). Through this activity I want to switch another activitity(for example, ChildActivity which will be same for every tab i.e. in every tab we will get instance of this activity) using Button click. This button is hardcoded in original TabActivity(TActivity). Now I am able to do up to this. But Now I want to switch between 'MainActivity' and 'ChildActivity' using same Button.

MainActivity:

class MainActivity ...{

  onCreate(){
        Btn.setOnClickListener(new OnClickListener(--) {
            public void onClick(--){
                    Intent intent = new Intent(getBaseContext(),ChildActivity.class);
                replaceContentView("MainActivity", intent);
  }});
}//MainActivity

public void replaceContentView(String id, Intent newIntent) {
        View view = getLocalActivityManager().startActivity(id,newIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_REORDER_TO_FRONT)) .getDecorView(); this.setContentView(view);
        }//replaceContentView

in ChildActivity:

public void hideCurrentActivity(){
Intent intent = new Intent(getBaseContext(),MainActivity.class);
        replaceContentView("ChildActivity", intent);
}
public void replaceContentView(String id, Intent newIntent) {
        View view = getLocalActivityManager().startActivity(id,newIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP) .getDecorView(); this.setContentView(view);
        }

Ok, now problem is that this code creates fresh activity everytime. So all previous data is getting lost once I switch to previous activity.But i don't want to create fresh activity instead just want to bring old one to front.

Can anybody help? Thanks in advance.

0

There are 0 answers