Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Application pause/resume state

Tags:

android

My question is can i get to know when the entire application gets paused/resumed start/stop etc. For example if i have 5 activities in my application. Whenever any activity gets paused/resumed android notify the activity by calling the onPause/onResume methods.

So there are two possible scenarios when my activity gets paused. 1. My activity-2 gets paused because my activity-3 gets invoked. 2. My activity-2 gets paused because of some outside activity like incoming call.

Here I am interested only tracking when my activity gets paused by outside activities not my own application activities.

So is there any android provided solution for this or do I have to write my customized solution.

Thanks Dalvin

like image 644
Dalvinder Singh Avatar asked Jun 03 '11 08:06

Dalvinder Singh


2 Answers

There is no solution provided by the API because it is not needed in most cases.

What you can do is to create an abstract activity and make all your activities inheriting from this abstract one. In this abstract activity, by overriding onCreate, onResume, onPause, onDestroy, you can manage to count how many of your own activities are "alive", and then determine the state of your application.

This could work but it's not really the Android phylosophy

like image 121
Guillaume Avatar answered Sep 28 '22 11:09

Guillaume


You can know the starting of the whole application on application.oncreate() but there is no indicator for the whole application pause. Most of the cases never needs it anyway.

So further read in the activity lifecycle and the application class.

Still you can do this option in your program by overriding the onPause in each class and save a value to the sharedPrefrences then check on this value all over the application

like image 39
Hazem Farahat Avatar answered Sep 28 '22 12:09

Hazem Farahat