Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can one detect an Android application launching?

Is it possible to detect when an app is executed (i.e., when the user clicks on the app's icon)? I attempted to register an intent of type Intent.ACTION_MAIN using a category of of type Intent.CATEGORY_LAUNCHER hoping this would let me know whenever an app is launched. The problem is, my broadcast receiver is never getting called.

Is this an illegal intent/category combination for which to register? Is there some method I can use to determine when an application launch occurs?

like image 620
w.donahue Avatar asked May 31 '11 01:05

w.donahue


People also ask

How can I check if an app running on Android?

To open Quick Settings, from the top of the screen, swipe down twice. To see the number of active apps running in the background: At the bottom left, tap # active apps. Or, at the bottom right, tap the number next to Settings and Power .

How do I find my first app launch Android?

How do you know if the app is opened for the first time Android? You can use the SharedPreferences to identify if it is the "First time" the app is launched. Just use a Boolean variable ("my_first_time") and change its value to false when your task for "first time" is over.

How do you detect when an Android app goes to the background and come back to the foreground?

The onPause() and onResume() methods are called when the application is brought to the background and into the foreground again. However, they are also called when the application is started for the first time and before it is killed. You can read more in Activity.


1 Answers

The application start Intent is not a broadcast, so there is no way to register a broadcast receiver and receive it. As previously answered here, there really is no way to detect the launch of the app. You could possibly write a service that polled the running tasks looking for the application's task (using the ActivityManager interface), but that's the best I can think of and it probably wouldn't be very performant.

like image 97
Femi Avatar answered Oct 22 '22 08:10

Femi