3

I have a problem with back button in the tabactivity and group activity.

Now I have a 4 tab, in a tab I have one more activity. The back button doesn't work with group activity and tabactivity. How can I make this work?

Here is my code:

for tabbar

 public class TabbarActivity extends TabActivity {

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.tabbar);

    TabHost tabHost = getTabHost();
    TabHost.TabSpec spec;
    Intent intent;
    Resources res = getResources();

    intent = new Intent().setClass(this, StartActivity.class);
    spec = tabHost.newTabSpec("ReweHaupt").setIndicator("ReweHaupt",
      res.getDrawable(R.drawable.home))

                  .setContent(intent);
    tabHost.addTab(spec);

    intent = new Intent().setClass(this, EinkauflisteActivity.class);
    spec = tabHost.newTabSpec("EinkaufListe").setIndicator("EinkaufListe",res.getDrawable(R.drawable.einkaufliste))
                  .setContent(intent);
    tabHost.addTab(spec);

    intent = new Intent().setClass(this,FilialesuchenActivitiy.class);
    spec = tabHost.newTabSpec("Filiarsuchen").setIndicator("Filiarsuchen",res.getDrawable(R.drawable.searchbuton))
                  .setContent(intent);
    tabHost.addTab(spec);

    intent = new Intent().setClass(this,NotizblockActivity.class);
    spec = tabHost.newTabSpec("Notizblock").setIndicator("Notizblock",res.getDrawable(R.drawable.einkaufliste))
                  .setContent(intent);
    tabHost.addTab(spec);






}

EinkauflisteACtivity.java

 public class EinkauflisteActivity extends ActivityGroup {

// das brauchen wir für groupactivity

public static EinkauflisteActivity group;
private ArrayList<View> history;

@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.einkaufliste);
    this.history = new ArrayList<View>();
    group = this;

    Button btnsenden = (Button) findViewById(R.id.btnsenden);
    Button btnscaner = (Button) findViewById(R.id.btnscaner);
    Button btnsuchen = (Button) findViewById(R.id.btnsuchen);

    // wenn wir button clicken, rufen wir neu activity
    btnsuchen.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            View view = getLocalActivityManager().startActivity(
                    "Systemhaus",
                    new Intent(v.getContext(), SuchenActivitiy.class)
                            .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP))
                    .getDecorView();
            replaceView(view);
        }
    });

}

public void replaceView(View v) {
    history.add(v);
    setContentView(v);
}

public void back() {
    if (history.size() > 0) {
        history.remove(history.size() - 1);
        setContentView(history.get(history.size() - 1));
    } else {
        finish();
    }
}

public void onBackPressed() {
    back();
}

public void onClick(View v) {
    // TODO Auto-generated method stub

}
talonmies
  • 70,661
  • 34
  • 192
  • 269
Lucky
  • 81
  • 11

1 Answers1

3

back button does not work here

you have to override on back pressed onBackPressed() in each of the activity and maintain a stack and pop the required activity

Pratik Butani
  • 60,504
  • 58
  • 273
  • 437
  • if you read correctly the tabactivity is a single activity which doesnot maintain your stack so on back press finish your activity.this is the way tab works you can change the tab but not go back to last tab like ios. – Harsh Dev Chandel May 22 '13 at 10:09