android - Navigate via back-button from child fragment back to parent activity -


i have main activity , 2 fragments. in main activity have navigation drawer navigates through fragments. handle button pressed this:

@override public void onbackpressed() {     if (getfragmentmanager().getbackstackentrycount() > 0) {         getfragmentmanager().popbackstackimmediate();     } else {         super.onbackpressed();     } } 

after navigating between 2 fragments, when hit button, last fragment backstack. however, navigating fragment fragment should not possible.

more clarity:

i have 1 activity (with navigation drawer) , 2 fragments. navigation drawer can go both fragments many times want. when hit button, want go main_activity.xml.

when navigate through activities, best way use intents (if understood question):

intent intent = new intent(this, mainactivity.class); startactivity(intent); 

Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -