3

I'm experiencing a strange issue on a new app I'm currently developing, where if I send the app to background (Home button), and then relaunch the app using the App Icon, all activities, except for the root activity are destroyed (on log I get OnDestroy for all activities, except for the root activity where OnResume is called).

If I send it to background and resume it from the current tasks, it resumes the app.

I have added android:launchMode="singleTask" to all the activities on the app manifest but it made no difference.

Every activity is started normally: startActivity(new Intent(this, nextClass));

Is there any way to resume the app when pressing the App Icon instead?

AndroidManifest.xml

<application
    tools:replace="android:icon"
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme"
    android:screenOrientation="landscape"
    android:configChanges="keyboardHidden|orientation|screenSize"
    android:name="com.example.game.classes.App">
    <activity
        android:name=".LaunchScreenActivity"
        android:label="@string/app_name"
        android:screenOrientation="landscape"
        android:launchMode="singleTask"
        android:configChanges="keyboardHidden|orientation|screenSize">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity
        android:name=".HomeActivity"
        android:label="@string/app_name"
        android:screenOrientation="landscape"
        android:launchMode="singleTask"
        android:configChanges="keyboardHidden|orientation|screenSize"/>
    <activity
        android:name=".PlayActivity"
        android:label="@string/app_name"
        android:screenOrientation="landscape"
        android:launchMode="singleTask"
        android:configChanges="keyboardHidden|orientation|screenSize" />
.
.
.

EDIT: Explanation to as not duplicate of App restarts rather than resumes

The difference between that situation and mine is that, on that case the main activity is launched on top of the other activities (you can press back to return to previous running activities). In my case the other activities are completely destroyed except for the launch activity which is resumed.

Community
  • 1
  • 1
Marco Batista
  • 1,410
  • 1
  • 20
  • 38
  • possible duplicate of [App restarts rather than resumes](http://stackoverflow.com/questions/19545889/app-restarts-rather-than-resumes) – HexAndBugs Jul 27 '15 at 09:25
  • Honestly I searched around and didn't notice that question. The major difference between that situation and mine is that on his case if you press "back" you would go back to the previous running activity. On my case if you press back you exit the app (the previous running activities are destroyed when you press the app icon) – Marco Batista Jul 27 '15 at 09:40

1 Answers1

3

After days searching for a solution.. I finally found the problem. The issue was adding android:launchMode="singleTask" to every activity.

I removed it from all activities except from the root activity and now it is working as I wanted.

Marco Batista
  • 1,410
  • 1
  • 20
  • 38
  • what about Pin Lock activity? Pin Lock screen will be destroyed in this case. I wish bring it back when click on App Icon – Huy Nguyen Jan 31 '20 at 02:58
  • The root activity is always launched on click of app icon if it has launch mode single task, provided you have not finished the root activity while launching other activities. This solution is not working – abhishek maharajpet Jul 11 '22 at 07:50