so I have an application with multiple activities. So when I switch from 1 activity to another and then click on the back button it works fine. But when I click on 1 activity then go out of the app and go back, it removes the main activity from memory so when you click on the back button, nothing happens. There are 2 possible solutions here, if there is somehow someway to detect if an activity is out of memory or if I can save the activity in memory. This is how I open the activity:
Intent intent = new Intent(context, QuoteActivity.class);
Gson gson = new Gson();
String quoteDataAsAString = gson.toJson(quoteData);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.putExtra("QuoteData", quoteDataAsAString);
context.startActivity(intent);
And these are the 2 activities:
<activity
android:name=".MainActivity"
android:launchMode="singleInstance"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".quote.activity.QuoteActivity"
android:launchMode="singleInstance"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".user.UserFeedBackActivity"
android:launchMode="singleInstance"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
This is what I have in the main view:
@Override
public void onStart() {
super.onStart();
if (QuoteActivity.isChangedWithFavourites()) {
gridView.setAdapter(new QuoteImageAdapater(getApplicationContext(), reader.getCorrectData(currentSection), section));
QuoteActivity.setChangedWithFavourites(false);
}
}
A gif showing it: https://i.imgur.com/YZIkBU1.gifv
And this is how it should be: https://i.imgur.com/hghjB9L.gifv
This problem occurs on both activities even when I don't call the finish method.
Edit: I figured it out I had to change launchMode to singleTop