0

I have some strange effects in my Android App.

I use a TabHoster with TabGroupActivities for each Tab. Works pretty good except the behaviour of the Back Button.

An Activity is launched and responds to the Back button. Then I start a Child Activity with a ViewSwitcher. When i hit the Back Button on View A Activity is dismissed as Expected. But it gets through the onBackPressed() of my Activity.

When i hit the Back Button on View B (detailView==true) the Method is not even Called. Instead of that the onBackPressed() of the TabGroupActivity is Called and I am not able to switch back to the first View.

@Override
public void onBackPressed() {
    if (detailView == true){
        vf.showPrevious();
        detailView = false;
    }
    else {
        super.onBackPressed();
    }
return;
}

Can Anybody explain this and/or tell me how to switch between Views in an Activity in an ActivityGroup?

Hernd DerBeld
  • 563
  • 1
  • 5
  • 7
  • Grouping activities in tabs is deprecated and should not be used. Its buggy, ugly and never worked very good. Use fragments instead and switch between them with FragmentTransaction.replace(). The fragment backstack handling will help you with switching back if you call popbackstack in onBackPressed. I added this as a comment since it doesn't quite answer your question. – Sebastian Olsson Feb 22 '12 at 15:42
  • i'm sure you are right but fragments have been introduced with with Android 3.0 (API Level 11) and that would leave over 80% of the Users out. [source](http://gigaom.com/mobile/android-fragmentation-not-so-bad-says-localytics/) So that is not an Option. – Hernd DerBeld Feb 23 '12 at 07:56
  • It won't and it is actually an option. You can use fragments for apps targeting Android 1.5 and later since there is an official support package backporting them. Se http://developer.android.com/sdk/compatibility-library.html . Just include the jar, extend FragmentActivity and enjoy! – Sebastian Olsson Feb 23 '12 at 08:21

1 Answers1

0

Few Days later i came to the Conclusion that it is FOR MY CASE the easiest solution to throw away the ViewSwitching stuff and transfer them to seperate Activities.

Sebastian Olsson is surely right with the fragments but it would be more effort for my specific App to rebuild everything to fragments.

Hernd DerBeld
  • 563
  • 1
  • 5
  • 7