http://stackoverflow.com/questions/4553605/difference-between-onstart-and-onresume
217
+50
|
OK, as my first answer was pretty long I won't extend it further so let's try this...
public DriveToWorkActivity extends Activity implements onReachedGroceryStoreListener { } public GroceryStoreActivity extends Activity {}
PLEASE NOTE: I've deliberately left out the calls to things like
super.onCreate(...) etc. This is pseudo-code so give me some artistic licence here. ;)
The methods for
DriveToWorkActivity follow...
OK, so it's another long one (sorry folks). But here's my explanation...
onResume() is when I start driving and onPause() is when I come to a temporary stop. So I drive then reach a red light so I pause...the light goes green and I resume. Another red light and I pause, then green so I resume. The onPause() -> onResume() -> onPause() -> onResume() loop is a tight one and occurs many times through my journey.
The loop from being stopped back through a restart (preparing to carry on my journey) to starting again is perhaps less common. In one case, I spot the Grocery Store and the
GroceryStoreActivity is started (forcing my DriveToWorkActivity to the point of onStop() ). When I return from the store, I go through onRestart() and onStart() then resume my journey.
I could put the code that's in
onStart() into both onCreate() and onRestart() and not bother to override onStart() at all but the more that needs to be done between onCreate() -> onResume() and onRestart() -> onResume() , the more I'm duplicating things.
So, to requote once more...
If you don't override
onStart() then this is effectively what happens. Although the onStart() method of Activity will be called implicitly, the effect in your code is effectively onCreate() -> onResume() or onRestart() -> onResume() . |
No comments:
Post a Comment