tags:

views:

38

answers:

1

My android application is consists of 20+ activities. I want to perform some task when application is in background (not an specific activity) and want to perform some other task when application is resumed. How to do this? I couldn't find onPause() and onResume() methods in Application class.

A: 

You can't do it globally because an application is just a set of activities that function pretty much independently from each other. The notion of something being in the background is really just that period when an activity is between onPause() and onDestroy().

One way for you to do what you're after would be to develop a bit of code that keeps track of when the first of your activities sees an onResume() and when the last of them sees an onPause() and uses those conditions to perform your tasks. You'd have to keep your data in a persisted store, such as shared preferences, so it doesn't vanish when the activity that created it gets destroyed.

Blrfl