Marco Dinatsoli
Marco Dinatsoli

Reputation: 10580

android is it possible to know time application spend in bg

any android application consists of many activities, only one activity can be in foreground. so I want to know for a specific application how many times it takes while it is in the background.

I mean this

application starts -> application go to foreground -> user plays in the application -> application goes to bg (here I want to save the time) -> application goes to foreground (here I want to save the time)

by minusing the two times I could know what is the time which the application spends in the background, but that is a very hard work, because I have to edit the on pause and on resumes for all the activities, I have more than 200 activity.

hypothenticlly

I think the mainfest had something to deal with my problem but I couldn't find it.

Upvotes: 0

Views: 48

Answers (2)

Venkata Krishna
Venkata Krishna

Reputation: 1603

Write one super activity for all your 200 activities and extend super activity for every activity. Handle the time measurement in Superactivity of onpause() and onresume() methods.

Example :

Parent activity:
class ParentActivity extends Activity
{
// here in onResume and onPause methods handle your time measurment things...
}

ChildAcitivity:

class ChildActivity extends ParentActivity
{
@override
public void onPause()
{
super.onPause();
}
@override
public void onResume()
{
super.onResume();
}
}

Upvotes: 1

Heinrisch
Heinrisch

Reputation: 5935

One solution would be to create your own activity class (class that extends Activity) and use that as a base for all your activities. In your own activity you can keep code that all activities share.

You would still have to edit all you activities to extend this new class, but it is much easier to add things like this.

Upvotes: 1

Related Questions