In my app I have 3 activities (I have more but lets stick with 3 for simplicity), lets call them A B and C where A is the main activity.
Activities B and C could be accessed multiple times from various locations in my app so in order not to overload the back stack and get outOfMemoryException
, I launch these activities using the flag FLAG_ACTIVITY_REORDER_TO_FRONT
.
However recently I started to experience some strange behavior from the back stack/back button where the back button closes the app instead of popping the top activity.
Here is an example of what is happening:
- user open app - back stack is "A"
- user opens activity B - back stack is "A B"
- user opens activity C - back stack is "A B C"
- user opens (not pressing back button) activity B again - back stack is "A C B"
- user presses back button
Expected behavior: back stack should be "A C" and activity C should be visible on the screen again.
Actual behavior: app closes.
I have confirmed the state of the back stack with adb shell dumpsys activity
and before pressing the back button the stack indeed looks like "A C B".
Any ideas why this is happening and how I can fix this?
edit
my device is LG V30 and running API 25. I have also found this. apparently this exists since API 19! I do not wish to start messing and using hacks with the back stack and looking for another solution.
edit 2
here is how i launch a new activity
Intent intent = new Intent(context, ActivityFavoriteShows.class);
intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
context.startActivity(intent);
and here is my manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.somepackage">
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<application
android:name=".pojos.MyApplication"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".activities.ActivityMain">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activity
android:name=".activities.ActivityShowInfo"
android:theme="@style/MaterialDrawerTheme.Light.DarkToolbar"/>
<activity android:name=".activities.ActivitySeasons"/>
<activity android:name=".activities.ActivityCast"/>
<activity android:name=".activities.ActivityCrew"/>
<activity android:name=".activities.ActivitySearch"/>
<activity android:name=".activities.ActivityFavoriteShows"/>
<activity
android:name=".activities.ActivitySettings"
android:theme="@style/AppTheme"/>
<service
android:name=".services.ServiceReadWrite"
android:exported="false">
</service>
</application>
</manifest>