-- Leo's gemini proxy
-- Connecting to republic.circumlunar.space:1965...
-- Connected
-- Sending request
-- Meta line: 20 text/gemini
I noticed some variation between devices so I tested various user actions on various devices and recorded the Android Activity lifecycle methods (e.g. onResume, onPause, onCreate, onStop) that got called. My results are below.
[Why? I want to detect whether the user is leaving the app or just transitioning from one activity to another. See my next blog posts Detecting whether an Android app is stopping (or starting) and Code for detecting when you leave an Android app for how to do it.]
Ensure the app process is stopped.
Start the app. It starts an Activity.
Start recording events.
Press "home" on the device.
⊞ table ⊞
HTC Wildfire S
Android 2.3.5 (API 10)
onSaveInstanceState onPause onStop
Nexus One Emulator (x86)
Android L (API 20)
onPause onSaveInstanceState onStop
When home was pressed, onPause and onStop were called in that order, and onSaveInstanceState was always called before onStop. The app was still running after the test.
Note that onSaveInstanceState can happen either before or after onPause.
This is consistent with the information given on the Android Activity API docs :
>
> Starting with Honeycomb, an application is not in the killable state until
> its onStop() has returned. This impacts when onSaveInstanceState(Bundle)
> may be called (it may be safely called after onPause() and allows and
> application to safely wait until onStop() to save persistent state.
Ensure the app process is stopped.
Start the app. It starts Activity1.
Press a button in the activity that launches Activity2.
Start recording events.
Press "home" on the device.
Results are identical to "Press the home button" above, with Activity2 receiving all the calls, and Activity1 not receiving any.
Ensure the app process is stopped.
Start the app. It starts an Activity.
Start recording events.
Press "back" on the device.
⊞ table ⊞
HTC Wildfire S
Android 2.3.5 (API 10)
onPause onStop onDestroy
Nexus One Emulator (x86)
Android L (API 20) (same as above)
When back was pressed, onPause, onStop and onDestroy were called. The app process was still running after the test.
onSaveInstanceState was not called, because there is no current state to resume - when you re-enter you will be back at the beginning.
Ensure the app process is stopped.
Start recording events.
Start the app.
⊞ table ⊞
HTC Wildfire S
Android 2.3.5 (API 10)
onCreate onStart onResume
Nexus One Emulator (x86)
Android L (API 20) (same as above)
When the app was started, onCreate, onStart and onResume were called in that order.
Start the app.
Start recording events.
Press the power button (turn off).
⊞ table ⊞
HTC Wildfire S
Android 2.3.5 (API 10)
onSaveInstanceState onPause
Nexus One Emulator (x86)
Android L (API 20)
onPause onSaveInstanceState onStop
When the phone was suspended, onSaveInstanceState and onPause were called in different orders, and onStop was called in some cases.
Start the app.
Press the power button (turn off).
Start recording events.
Press the power button (turn on).
Unlock the device.
⊞ table ⊞
HTC Wildfire S
Android 2.3.5 (API 10)
onResume
Nexus One Emulator (x86)
Android L (API 20)
onRestart onStart onResume
When the phone was resumed, onResume was always called, and onRestart and onStart were sometimes called.
Ensure the app process is stopped.
Start the app.
Press "home" on the device.
Start recording events.
Start the app.
⊞ table ⊞
HTC Wildfire S
Android 2.3.5 (API 10)
onRestart onStart onResume
Nexus One Emulator (x86)
Android L (API 20) (same as above)
When the app was restarted after pressing home, onCreate was not called, but onRestart, onStart and onResume were (in that order).
Ensure the app process is stopped.
Start the app.
Press "back" on the device.
Start recording events.
Start the app.
⊞ table ⊞
HTC Wildfire S
Android 2.3.5 (API 10)
onCreate onStart onResume
Nexus One Emulator (x86)
Android L (API 20) (same as above)
When the app was restarted after pressing back, onRestart was not called, but onCreate, onStart and onResume were (in that order).
This is consistent with the idea that pressing back effectively ends the app, but pressing home effectively pauses it.
Ensure the app process is stopped.
Start the app. It starts Activity1.
Start recording events.
Press a button in the activity that launches Activity2.
⊞ table ⊞
HTC Wildfire S
Android 2.3.5 (API 10)
Activity1.onSaveInstanceState Activity1.onPause Activity2.onCreate Activity2.onStart Activity2.onResume Activity1.onStop
Nexus One Emulator (x86)
Android L (API 20)
Activity1.onPause Activity2.onCreate Activity2.onStart Activity2.onResume Activity1.onSaveInstanceState Activity1.onStop
The later version of Android called onSaveInstanceState much later in the process. This is consistent with the documentation for the Activity Lifecycle.
In both cases Activity1's onPause was called before any methods were called on Activity2.
In both cases Activity1's onStop was called after all methods were called on Activity2.
Activity2's methods were called just as if it were the starting activity of a freshly-launched app (see "Start the app" above).
Activity1's methods were called just as if the home button had been pressed.
Ensure the app process is stopped.
Start the app. It starts an Activity.
Start recording events (in our activity only).
Press a button in the activity that launches the Android web browser.
Results are identical to "Press the home button" above.
Ensure the app process is stopped.
Start the app. It starts Activity1.
Press a button in the activity that launches Activity2.
Start recording events.
Press "back" on the device.
⊞ table ⊞
HTC Wildfire S
Android 2.3.5 (API 10)
Activity2.onPause Activity1.onRestart Activity1.onStart Activity1.onResume Activity2.onStop Activity2.onDestroy
Nexus One Emulator (x86)
Android L (API 20) (same as above)
Activity2 sees the same calls as in "Press the back button to exit" (i.e. it is destroyed).
Activity1 see the same calls as in "Restart the app after pressing home" (i.e. it is resumed).
Ensure the app process is stopped.
Start the app. It starts an Activity.
Press a button in the activity that launches the Android web browser.
Start recording events (in our activity only).
Press "back" on the device.
Results are identical to "Restart the app after pressing home" above.
See my next blog post for how to detect whether we are leaving the app, or just transitioning between activities: Detecting whether an Android app is stopping (or starting).
Originally posted at 2015-06-04 23:31:38+00:00. Automatically generated from the original post : apologies for the errors introduced.
-- Response ended
-- Page fetched on Sun May 19 06:13:37 2024