0

How can I close a tab when I am leaving that tab.

or

How can I start an activity when I am clicking a tab each time.

Zach Rattner
  • 20,745
  • 9
  • 59
  • 82
A J
  • 4,542
  • 5
  • 50
  • 80

1 Answers1

1

You need to set tab change listener

getTabHost().setOnTabChangedListener(new OnTabChangeListener() {

@Override
public void onTabChanged(String tabId) {

int i = getTabHost().getCurrentTab();
 Log.i(" ANN CLICK TAB NUMBER",  + i);

    if (i == 0) {
            Log.i("Inside onClick tab 0", "onClick tab");

    }
    else if (i ==1) {
            Log.i("Inside onClick tab 1", "onClick tab");
    }

  }
});

Depend on your activity stack if your current exactly on top of the parent activity you can just finish current actvity and it will go to previous activity. If you want to clear all activity stack and start over new activity try

Intent intent1 = new Intent(context, activity.class);
             intent1.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
             intent1.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);  
            startActivity(intent1);
DjHacktorReborn
  • 2,908
  • 2
  • 20
  • 29
  • I saw that ans But please tell me how can I restart or finish that that activity using that TAB NUMBER – A J Mar 07 '13 at 08:57
  • How can I open that intent1 inside a tabview – A J Mar 07 '13 at 09:23
  • That activity is opeing but not inside tabview please tell me how to – A J Mar 07 '13 at 09:28
  • i think if you do searching you got might have got your answer anyways this may help you http://stackoverflow.com/questions/1306689/launching-activities-within-a-tab-in-android – DjHacktorReborn Mar 07 '13 at 09:32