Android : how to know when an app enters or the "background" mode? -


I am trying to get the following with Android:

  • When the app is in the background, a thread selects a server every time and again to retrieve the data and informs the user if the new data is available. I am using a service for it, okay.

  • When the app is in "active" use, i.e. its activity is seen, then voting should be stopped because it can interfere with other user actions.

I do not have a way to detect infection between the "active" or "background" of the app. Onusous () activity methods are not helpful, because any activity can be hidden in the same way during "active" use. My understanding is that the app does not distinguish between 2 states.
Can the Home button be pressed? What is another way to differentiate?
I am thinking of applying the iPhone App Representative method to applicationDidEnterBackground is the right way to consider with Android? Or will I use another approach?

Thank you.

I'm going for reference. In between onResume and onPause your activity is 'active', that is, it is on screen and user can interact with it. If the onPause method of your activity is called, then you should consider that it is no longer 'active' and the user will not be able to use it again until the call to onResume Can not interact with If you want to track it in your service, you have to do it manually.

This is probably achieved by calling a method in your service by calling activity # percussion , which increases a counter or sets a flag and onPause Back to the change If you have many activities, then you will probably need a counter, possibly a AtomicInteger , and use it to determine if you have voted yourself When should I start

I may have copied a bit of time When I reach the Counter 0, check it again, and if it is still then 0 will start again. This is an onPause of another and onResume of another.

will have an account for the gap

Comments