Hello, I Have one Activity and two fragments, I want to come back from Fragment 2 to fragment 1. How to go back?
Asked
Active
Viewed 834 times
-14
-
1when you move from one fragment to another fragment, add your fragment to backstack. And when get back from fragment2 to fragment1 call popBackStack(). – sumit singh Mar 21 '16 at 10:35
-
It's help, but, when I go from frag 1 to frag 2, I chagne Toolbar title (from Profile to Edit profile), but when I press back Button, Toolbar title does not changed back. How can i Solve it? Sorry for my bad English – Karo Hovhannisyan Mar 21 '16 at 11:03
-
where you set the toolbar title? – sumit singh Mar 21 '16 at 11:07
-
frag 1 in Activity frag 2 in Frag 2 ((AppCompatActivity) getActivity()).getSupportActionBar().setTitle("Edit Profile"); – Karo Hovhannisyan Mar 21 '16 at 11:09
-
set the toolbar title in onCreateView() or onResume() method of your fragment. – sumit singh Mar 21 '16 at 11:12
-
when I press back the title of toolbar didnt change to "Profile" i set the toolbar in onCreateView, and try it in onResume too, but its not work – Karo Hovhannisyan Mar 21 '16 at 11:50
-
see this it might be helpful-http://stackoverflow.com/questions/6503189/fragments-onresume-from-back-stack – sumit singh Mar 21 '16 at 11:57
2 Answers
-2
Before going forward, add your fragment to back stack and later call popBackStack
Marius Kaunietis
- 645
- 4
- 17
-
It's help, but, when I go from frag 1 to frag 2, I chagne Toolbar title (from Profile to Edit profile), but when I press back Button, Toolbar title does not changed back. How can i Solve it? Sorry for my bad English – – Karo Hovhannisyan Mar 21 '16 at 11:04
-
So.. just change it back to whatever you want after popping back stack. – Marius Kaunietis Mar 21 '16 at 11:10