Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android - Back stack is not maintained when app is moved to background and bring to foreground

I am having 3 activities in my app and the flow is like A->B->C. When I was in activity C, I moved the app to background by pressing the home button. I brought the app to foreground again and it showed activity C as expected. When I press back key, it's closing the app and B and A are not shown.

I put the launch mode for A, C as single instance and for B, nothing is specified. I want to have one instance for all my activities. I have tried by changing the launch mode to single task(with permutation and combinations of all activities) and it didn't work.

Here is my manifest looks like for activity declaration

<application
    android:name=".MyApplication"
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    tools:ignore="GoogleAppIndexingWarning"
    android:roundIcon="@mipmap/ic_myway_circular_launcher"
    android:supportsRtl="true"
    android:theme="@style/AppTheme.NoActionBar">
    <activity
        android:name="A"
        android:launchMode="singleInstance">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

    <activity
        android:name="B"
        android:windowSoftInputMode="adjustPan" />
    <activity
        android:name="C"
        android:launchMode="singleInstance"
        android:windowSoftInputMode="adjustPan"/>
</application>

Can someone tell me how to maintain the back stack always even when the app is opened from background?

Thanks in advance.

like image 815
Kameswari Avatar asked Dec 04 '25 16:12

Kameswari


1 Answers

After a lot of research, I found that it's the problem with the launch mode. As per Android documentation, for this mode, the system doesn't launch any other activities into the task holding the instance. The activity is always the single and only member of its task

But I wonder the issue is only coming when the app brought to foreground from background. If it is continuously running on foreground, issue is not there.

Finally, I changed it to default mode and it's working now.

like image 101
Kameswari Avatar answered Dec 06 '25 08:12

Kameswari