Ahmed Fahmy Ahmed Fahmy - 23 days ago 9
Android Question

Closing background Activity

when i'm on the MainActivity in my app then press the setting menu in the action bar a new fragment is opened..there are two problems here

1- when i'm on the setting fragment then i press the multi-tasking button i found two windows for my app not one..the MainActivity and the settings

2- if i press the setting window when i'm still on multi-tasking window then press the back button it should take me to MainActivity instead it closes the app.

So now what i want to do is

1- close the MainActivity from the background once i open settings

2- if i press multi-tasking button and choose settings window in my app then press back it takes me to the MainActivity not close the whole app.

here is how i defined my activities in manifest file

<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=".Settings"
android:label="@string/settings_title"
android:excludeFromRecents="true">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.example.android.bee.MainActivity"/>
</activity>
<receiver android:name=".Notifications"/>
</application>


hope the image helps visualizing it..thanks alot
this is what happens when i press tthe multi-tasking button after i open settings from MainActivity

T.S T.S
Answer

Remove the android:launchMode="singleInstance" attribute.