Reputation: 23606
I need a way for my Activity to known that it's going into the background, and not when it's getting killed. I thought about hooking at onStop(), but onStop() is called for both cases. In other words, is there a way to tell if when my Activity is moving into the background and not getting killed?
Upvotes: 1
Views: 1584
Reputation: 3859
How about the onPause() method? From the docs:
Called as part of the activity lifecycle when an activity is going into the background, but has not (yet) been killed.
Upvotes: 2
Reputation: 77722
What are you looking for? Or, more importantly, what are you going to do if you detect it? By definition, onPause()
is when you should be starting to pause your worker threads and save your data back to persistent storage. In onDestroy()
, you can call isFinishing()
to see if you're on your way out or just destroying and then recreating yourself because of something like an orientation change.
Upvotes: 1