I've tried googling, and looking on stackoverflow as well, but I can't seem to find any satisfying answer as to how the "App lock" applications(eg: ZDBox, App Lock, etc..) work. Is there a service that runs in the background continuously polling to see if the app is launched and tries to kill it? Or is there a way to intercept launch intents for new activities?
3 Answers
there is a service running in the background to read the activity stack. if find new activity, will start the passwordActivity

- 246
- 3
- 4
-
4Where can I find more details on this? I wonder how much battery it would eat up if service constantly keeps running in background. – ABDroids Aug 26 '13 at 10:03
-
3@user930177, according to you, the service is running continuously in the background but can you tell me one thing; there are chances when android kills the serivces itself; in that case what is happenning..??? – Custadian Mar 13 '14 at 18:44
-
1Thanks for your answer. But I got another problem. After user enters correct password, locked app is open. But the service is running, so password activity starts again. – Phuc Tran Nov 16 '14 at 16:03
they are watching logcat output. whenever you start an activity, you can find specific logcat. like this,
I/ActivityManager( 585): Starting activity: Intent { action=android.intent.action...}
if this logcat printed by locked app, locker service starts password screen.

- 341
- 4
- 9
-
5is it possible method..... ??? can u explain this idea... how we can read the log cat of other application??? – Vikky May 14 '13 at 15:23
-
Logs does not a secret, in Android Studio you can catch all logs – Kirill Shalnov Apr 01 '17 at 13:31
-
Might this be vulnerable to other apps that use the same tag logging the same data? – SOFe Aug 21 '17 at 09:42
MORE MODERN ANSWER (Nov 2022):
This can be handled by the new app usage API
The system collects the usage data on a per-app basis, aggregating the data over daily, weekly, monthly, and yearly intervals. The maximum duration that the system keeps this data is as follows:
Daily data: 7 days Weekly data: 4 weeks Monthly data: 6 months Yearly data: 2 years For each app, the system records the following data:
The last time the app was used
The total length of time the app was in the foreground for that time interval (by > day, week, month, or year)
Timestamp capturing when a component (identified by a package and activity name) ?> moved to the foreground or background during a day
Timestamp capturing when a device configuration changed (such as when the device orientation changed because of rotation)
A background service can be used to constantly watch for updates to timestamps for specific apps regarding when they moved to the foreground with the API above.
note: It seems that starting from Android 5/6/7 and higher you cannot read info about other apps, including their status and logs. I believe this makes looking in logcat no longer work. If anyone can confirm this please comment below! Also, the getRunningTasks function to view active activities is now deprecated.

- 407
- 2
- 7
- 19