Ahmed Fahmy Ahmed Fahmy - 1 year ago 74
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"

<action android:name="android.intent.action.MAIN" />

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

<activity android:name=".Settings"
<receiver android:name=".Notifications"/>

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

Answer Source

Remove the android:launchMode="singleInstance" attribute.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download