I've been developing Android for 3 years, and this is still a hard thing to decide when it comes to the similar scenario. Nowadays, I believe most of the applications has a multi-step screen / flow.
For example, a booking flow. You need to proceed through several steps like select ticket, select seat, select product details, then enter personal details. Each step might need some data from the previous step.
I did a lot of researches on this, and read a lot of posts from reddit and SO, but still don't come to a conclusion.
Google told us to use fragments for flexible UI, and Jake Wharton also mentioned that 'You can use fragment, but don't use its backstack.'
Should i use single activity with multiple fragments as steps, or separate activities, with each activity representing a step?
Currently, i am using the first approach, by adding fragment into backstack, and restore their data state when popping (user press back). However, i need to set 'freezesText' on all textviews and make sure recyclerview adapter is in the fragment onCreate to preserve its state. There might be more pains incoming.
I even wrote a custom fragment container / manager to maintain my fragments seamlessly.
I see many sources mentioning that activity transitions are more expensive. Thus, I wrote two apps simulating the scenario to compare the performance. Both apps served the same screen and result, developed with MVP arch. These apps are pulling news into a list, and u can press them to view detail.
Single activity with two fragments: https://github.com/Veeyikpong/fastNewsFragment
Separate activities: https://github.com/Veeyikpong/fastNewsActivity
I compared them with Android studio profiler, noticed theres not much different in memory consumption, but the separate activities app have lesser code size (10216kb) and the one with fragments is 14000kb.
Based on the test, i didn't notice much different between them, and of course develop with just activities is much faster. Am i doing the test wrong? Please advice on this scenario.
Or should i try the new Navigation component by Google? They say it will handle the complexity of FragmentTransactions for you.