Skip to content Skip to sidebar Skip to footer

Android Bottom Navigation - Maintaining Activity State

I know it's recommended to use Fragments instead of Activities when working with Bottom Navigation. Due to the current design, I want to avoid having to convert all the Activities

Solution 1:

You could use FragmentStatePagerAdapter in the Activities. However, you should update to fragments, they are designed to handle your situation. The migration is not that bad, most of the logic can simply be copied over.

Solution 2:

My current app has the same kind of design. Bottom menu has different icons that launches activities and each activity has fragments in it.

I solved the problem by using FLAG_ACTIVITY_REORDER_TO_FRONT before launching the bottom menu activities.

case R.id.ic_house:
                        Intent intent1=newIntent(context, HomeActivity.class);
                        intent1.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
                        context.startActivity(intent1);
                        break;
    case R.id.ic_more:
                        Intent intent2=newIntent(context, MoreActivity.class);
                        intent2.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
                        context.startActivity(intent5);
                        break;

This question is 3 years old but maybe someone else finds this solution helpful.

Post a Comment for "Android Bottom Navigation - Maintaining Activity State"