• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Question regarding tabs retaining fragment state

CodeSpace

Lurker
Hi,

I'm trying to replicate an iOS app in Android. I have tab up an activity that holds 4 different fragments, and these are loaded using the .replace() method, depending on which tab is selected.

That's all fine. Working as intended.

My issue is that these 4 tabs also lead to other fragments (in my attempt to replicate iOS pushing view controllers within a tab). These fragments have to be native to the tab that they are loaded from. The problem is that if I load one of these fragments and then change tab the app tends to die rather quickly.
Does anyone have any recommendations about how to achieve what I'm after?

tl;dr: Here's a simple diagram in case my question isn't very clear:

MainActivity (Holds tabs (4 different tabs))
- Tab1 -> TabFragment1
- Tab2
- Tab3
- Tab4

So: TabFragment1 needs to be local to Tab1. If I load up TabFragment1 and switch to Tab2, and then switch back to Tab1, I would like to have TabFragment1 still active.

Thanks in advance!
 
Back
Top Bottom