Posts Handling back button press Inside Fragments
Post
Cancel

Handling back button press Inside Fragments

http://vinsol.com/blog/2014/10/01/handling-back-button-press-inside-fragments/

https://github.com/Infernus666/FragmentOrientedApplication

minimal

1
2
//on fragment itself call :
getFragmentManager().popBackStack();

or handle the click on parent (aka activity)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
//handle click on activity shows the fragment
	@Override
	public void onBackPressed() {
		int count = getFragmentManager().getBackStackEntryCount();
		if (count == 0) { //when use it with drawer make it 1
			super.onBackPressed();
		} else {
			getFragmentManager().popBackStack();
		}
	}

//warning the beginTransaction, should be use addToBackStack
//source - http://www.tech.theplayhub.com/how_to_implement_onbackpressed_in_android_fragments/
FragmentManager fragmentManager = getFragmentManager();
fragmentManager.beginTransaction().replace(R.id.frame_container, fragment).addToBackStack(null).commit();

Codepath - Creating and Using Fragments

https://guides.codepath.com/android/Creating-and-Using-Fragments#managing-fragment-backstack

Providing Proper Back Navigation

http://developer.android.com/training/implementing-navigation/temporal.html

Handle Back Button Event in Fragment andorid – ViewPager Android

http://www.quicktips.in/how-to-handle-back-button-event-in-fragment-andorid-viewpager-android-tutorial/

origin - http://www.pipiscrew.com/?p=4028 android-handling-back-button-press-inside-fragments

This post is licensed under CC BY 4.0 by the author.
Contents

Trending Tags