tags:

views:

85

answers:

2

In the Android Application Fundamentals it says that after the call to the onStart()-method of the activity lifecycle either the callback method Resume() or onStop() is called. In case of an "normal" Start of an activity the system calls onCreate(), onStart(), onResume(). But does somebody know an example where onStart() - onStop() are executed one after another?

A: 

According to the flowchart on the page provided, it is not possible for onStop() to be called without onResume() being called. I could think of some potential scenario in which the system shuts down the application in the middle of starting it up, but I have no clue what or how such a scenario would be triggered, or if it even exists.

As pointed out by Tseng, it's possible that a task will never be brought to the foreground (I'm thinking of say, the task that syncs the phone with an Exchange server). I imagine Such a task will never have onResume() or onPause() called.

Darth Android
Haven't tried, but maybe by calling finish() inside of onStart()? (Even though it doesn't really makes much sense to call it there :P)
Tseng
@Tseng If we're allowing that, then you could simply call `onStop()` yourself from inside `onStart()` - I read the question as asking for scenarios that the AndroidOS would present.
Darth Android
After taking some time to read the life cycle once again, your statement is then wrong too, as the documentation says:onStart():Called just before the activity becomes visible to the user.Followed by onResume() if the activity comes to the foreground, or onStop() if it becomes hidden.
Tseng
@Tseng Good point: A background task may never get any foreground action, in which case an `onResume()` will never be called.
Darth Android
+1  A: 
  1. From your activity, start another activity that is not full-screen (for example give it android:theme="@android:style/Theme.Dialog").

At this point your first activity has had onPause() called but not onStop() because it is not in the front but still visible.

  1. Press home.

At this point onStop() is called for your first activity.

  1. Relaunch your app.

At this point onStart() is called for your first activity, but not onResume() because it still has the non-full-screen activity on top of it.

  1. Press home.

At this point onStop() is called on the first activity, without having gone through onResume().

hackbod
Thanks for your proposal. It works!
Coco