I have a main activity with 2 fragments. One of the fragments is a form. After submitting the form, a new results activity is a launched which has a back navigation button. When I press this back button, I am taken back to the form, but my form is cleared. I want to retain all the data which I entered initially before submitting. How can I achieve this?
Asked
Active
Viewed 58 times
0
-
https://stackoverflow.com/questions/7992216/android-fragment-handle-back-button-press , https://developer.android.com/training/implementing-navigation/temporal – Nov 18 '18 at 10:36
-
My fragments are in main activity and the problem happens when I navigate back to it from the search result activity. I am not switching from one fragment to another – Deepa Sreekumar Nov 18 '18 at 10:45
-
Go for this https://stackoverflow.com/questions/41605669/android-fragment-back-press-without-any-data-loss?rq=1 – Rishav Singla Nov 18 '18 at 11:20
2 Answers
1
You have to remember about active / fragment lifecycle. When you back to your activity / fragment you have to refresh method @onResume. So if you forgot about @onResume method you have to implement overridden and put there your missing methods.

Wiktor Kalinowski
- 79
- 1
- 5
-
It is retaining the values when I press the hardware back button, but not the soft button in the app – Deepa Sreekumar Nov 18 '18 at 10:32
0
I was able to solve the issue by setting the launchMode of the activity that held the fragments as singleTop in the manifest file.
android:launchMode="singleTop"

Deepa Sreekumar
- 51
- 8