I have an App with a main activity and a popup activity, if I stay in the app there is no problem. But if the popup activity is open and you re-enter the app from the recents screen only the popup activity is shown. If you then close it you don't return to the main activity but the app closes completely.
This opens the popup activity from the main activity:
intent = new Intent(ctx, popupActivity.class);
intent.putExtra("rackName", resultChest.get(2));
ctx.startActivity(intent);
And here is the method which closes the popup activity:
@Override
public boolean onTouchEvent(MotionEvent event) {
finish();
return super.onTouchEvent(event);
}
The AndroidManifest.xml:
<application
android:allowBackup="true"
android:icon="@mipmap/ic_lchr"
android:logo="@mipmap/ic_lchr"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_lchr_round"
android:supportsRtl="true">
<activity android:name=".MainActivity"
android:theme="@style/AppTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activity android:name=".popupActivity"
android:theme="@style/popupTheme"
android:launchMode = "singleInstance">
</activity>
</application>
Solution:
as @RedWolf mentioned android:launchMode = "singleInstance"
causes the activity to open in another task which causes my problem.
To resolve this and prevent the popup activity to open twice I had to use android:launchMode = "singleTop"
for the popup activity.
Do not use android:launchMode = "singleInstance"
, it will create a new task.