2

I am currently trying to monitor applications being launched and closed under Android. I need to create Android Service app that accumulate statistics (Time, AppName) about starting and terminating selected apps.

I clear understand Processes and Application Lifecycle https://developer.android.com/guide/components/activities/process-lifecycle.html

And I know how to detect running app How can I check if an app running on Android?

Anyway are there any Android events to sucbscribe to listen for it?

Is it possible to do at least for MainActivity of the app?

Should monitored app have implemented some kind of interprocess Broadcast Messenger?

Thank you!

NoWar
  • 36,338
  • 80
  • 323
  • 498
  • you can start a service at onStop() preferably at onPause() of your main activity to detect if your application was being closed or not. keeping in mind that your main activity will always be running throughout your application and will only be destroyed when your application stops. – Umair Feb 09 '18 at 05:56
  • @Umair I mean. I want to create some independed Service that scans App1, App2 and App3. I assume should be system events to detect fact of starting and termination of Andoid app. Are there any those events? – NoWar Feb 09 '18 at 05:59
  • you want to detect about your app or the other applications ? I believe we can detect about our app but need root or special permissions about other apps. – Umair Feb 09 '18 at 06:15
  • And yes you can use either some broadcast reciver or call any other service to check when your app started or finished. – Umair Feb 09 '18 at 06:16
  • @Umair I am currently trying to monitor other applications being launched and closed. – NoWar Feb 09 '18 at 06:18
  • As far as I know you can't do that without root privileges, but let's see if someone finds a solution to this. – Umair Feb 09 '18 at 06:28
  • 1
    You can try using [`UsageStatsManager`](https://developer.android.com/reference/android/app/usage/UsageStatsManager.html) – shhp Feb 09 '18 at 06:37
  • 1
    @sshp From that page: "This API requires the permission android.permission.PACKAGE_USAGE_STATS, which is a system-level permission and will not be granted to third-party apps" – GPS Feb 09 '18 at 06:52
  • @GPS Hi! I am intrested to detect launched and closed app `EVENTS` if they exist. – NoWar Feb 09 '18 at 07:04
  • @shhp Well... It is not whant I am asking for exactly. I am intrested to detect launched and closed app `EVENTS` if they exist. – NoWar Feb 09 '18 at 07:05
  • Refer to [this answer](https://stackoverflow.com/questions/35172075/detect-which-app-has-been-launched-in-android/35172468#35172468). You have to do some extra work if you want to know which app is launched instantly. – shhp Feb 09 '18 at 07:33

0 Answers0