How do apps for using Android monitor work?

I want to write an application that registers the use of other applications on my phone.
So, for example, I get the time when I logged in to Facebook.

I understand that there is no way to make the broadcast compiler wake up every time Facebook starts. Another way is to have a service that always runs in the background, and checks to start applications and puts it to sleep every second or so, but I think it will speed up my battery.

So what is the best way to do this? is there any magazine i can look at?

+2
source share
1 answer

- . , , , , . , . . , :

ActivityManager am = (ActivityManager) this.getSystemService(ACTIVITY_SERVICE);
List< ActivityManager.RunningTaskInfo > taskInfo = am.getRunningTasks(1); 
Log.d("topActivity", "CURRENT Activity ::"
            + taskInfo.get(0).topActivity.getClassName());
ComponentName componentInfo = taskInfo.get(0).topActivity;
componentInfo.getPackageName();

:

<uses-permission android:name="android.permission.GET_TASKS"/>
+2

All Articles