I have in my activity a BottomNavigationView
. I am trying to create a separate backstack for each item of BottomNavigationView
. I used this answer to do the same but I am having problem saving the HashMap
mStacks
on screen rotation. As HashMap
is serializable, I saved it in the outState
bundle provided in onSaveInstanceState
function but I got the error that one of the fragment lets say MyFragment
in my app is not Serializable
so what I did was implemented Serializable
for MyFragment
, but again I got the error that the FragmentAdapter
present inside MyFragment
is not serializable. Now I can't think of any way to save mStacks
on screen rotation. Do you know any way to do so? Please help me
Asked
Active
Viewed 78 times
0

Kartik Watwani
- 629
- 8
- 20
-
1You need both the Key and the Value of the HashMap to be serializable too. Neither Stack nor Fragment implement the serializable interface. You may be able to extend these classes & implement Serializable to get what you need. – Gary99 Nov 24 '17 at 15:17
-
@Gary99 Yes that is the reason I implemented serializable for fragment but the fragment which I am trying to serialize has FragmentAdapter and that is not serializable. – Kartik Watwani Nov 24 '17 at 15:20
-
1MyFragmentAdapter extends FragmentAdapter implements Serializable {}? – Gary99 Nov 24 '17 at 15:25
-
@Gary99 Oh, I thought the `FragmentPagerAdapter` provided by android was Unserializable, but as a second thought, will saving all Fragment stack be efficient ? – Kartik Watwani Nov 24 '17 at 15:26
-
1Sorry, not sure. – Gary99 Nov 24 '17 at 15:31
-
No problem, thank you for the help anyways :) – Kartik Watwani Nov 24 '17 at 15:33
-
1well why don't we store only positions accordingly and then get it via bundle on other side after rotation. ? – vikas kumar Nov 24 '17 at 15:53
-
1and rest of the data can be saved in model which can be serializable and can be easily retrieved after screen rotation using again bundle. – vikas kumar Nov 24 '17 at 15:54
-
Yes, I thought of it few minutes back. I will try it. – Kartik Watwani Nov 24 '17 at 16:12