1

I've inherited a project that starts activity A which in turn starts activity B. If I press the Android Home button and then click on the app icon again, I get activity A vs B.

Looking at the life cycle I'm seeing this.

Click Icon ->Activity A Launch->onCreate->onStart->onResume
Click on context menu that starts Activity B->onCreate->onStart->onResume
Click on Android Home Button Activity B->onPause 
Click on App Icon on the Android Home Screen (to resume)
Activity B's onDestory is called followed by Activity A ->onCreate->onStart->onResume.

Any high level thoughts as to what to look for that would cause the onDestroy vs onResume?

Manifest Declarations:

Activity A


 <activity
            tools:replace="android:theme,android:label"
            android:name="WebViewActivity"
            android:configChanges="orientation|screenSize"
            android:label="@string/app_name_pro"
            android:launchMode="singleTask"
            android:theme="@style/MyTheme.AppCompat.NoAB">
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
            <intent-filter>
                <action android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED"/>
            </intent-filter>

            <meta-data
                android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED"
                android:resource="@xml/device_filter"/>
        </activity>

============================

Activity B

<activity
            android:name="OwaViewerActivity"
            android:label="@string/owa"
            tools:replace="android:theme"
            android:launchMode="singleTop"
            android:configChanges="orientation|screenSize|keyboardHidden"
            android:theme="@style/MyTheme.AppCompat.NoAB"
            android:parentActivityName="WebViewActivity">
            <meta-data
                android:name="android.support.PARENT_ACTIVITY"
                android:value="WebViewActivity"/>
            <intent-filter>
                <action android:name="android.intent.action.SEARCH"/>
            </intent-filter>
            <meta-data
                android:name="android.app.searchable"
                android:resource="@xml/searchable"/>
        </activity>
justdan0227
  • 1,374
  • 18
  • 48
  • Could you please paste related parts from manifest? – guness Nov 07 '17 at 22:05
  • In order to gain some memory, the system kill your app activities, so this behavior doesn't happen continuously, if there is no need to memory the system won't remove your app stack and you will start from you ended (on resum in the activity B). –  Nov 07 '17 at 22:08
  • Is Activity A launcher Activity? If yes then you might be facing issue like this https://stackoverflow.com/questions/19545889/app-restarts-rather-than-resumes – NinjaCoder Nov 07 '17 at 22:15
  • @NinjaCoder yes it is the Launcher App. I'll have a look at your link – justdan0227 Nov 09 '17 at 16:05
  • So I had a look at the link. That thread does not describe what I'm seeing. The fact that Activity B is getting the onDestroy when the App Launcher is clicked again is what is baffling me. This is the only app running so its not like the OS is terminating it. Again its legacy code so trying to find the needle in the haystack. – justdan0227 Nov 09 '17 at 16:24
  • 1
    Have you played around with the launchMode at all? Try deleting those attributes in your manifest to see if that fixes the lifecycles. If so, you will at least know where to start looking. – tim.paetz Nov 17 '17 at 22:18
  • @tim.paetz I'll try that however the main activity has no problems if you go to the home screen and back. Had got to be the way that Activity is being launched that is causing the onStop vs just the onPause from getting called. – justdan0227 Nov 20 '17 at 15:21

1 Answers1

2

So when in doubt, create a simple app. Turns out that the home button does generate an onStop and then should if the icon is tapped to relaunch, call onStart and on Resume. Turns out the SingleTask is what is causing the onDestory to happen. If I remove the SingleTask the app works as it should. Now I have to go back and find out why the legacy code was using Single Task!

justdan0227
  • 1,374
  • 18
  • 48