Get Android app launch source from Application context

Viewed 84

Is it possible from the Application class onCreate method (not Activity!!) to identify how the app has been launched?, like if it was from the Launcher or Push Notification or a boot complete broadcast receiver etc'

Also, is there a way to get the Intent object (if exists) which caused the launch, from the Application onCreate?

Basically what I am interested is to recognize if it was from Launcher or not and get the Intent if exists. All this, in the Application class, and not Activity.

2 Answers

Is it possible from the Application class onCreate method (not Activity!!) to identify how the app has been launched?, like if it was from the Launcher or Push Notification or a boot complete broadcast receiver etc'

No, sorry.

Also, is there a way to get the Intent object (if exists) which caused the launch, from the Application onCreate?

No, sorry.

First of all, I don't believe it's possible to check whether the app has been launched by the launcher directly, but rather with a process of elimination. Technically there is a way to get the Intent, which was used to launch the App in the Application's onCreate.

Since you can use Intent to start Activities, not Applications, you can use registerActivityLifecycleCallbacks to register an onActivityCreated callback in your App's onCreate, which gives you access to the created activity. Once you have the activity object, you can call activity.getIntent() to get the Intent object.

The onActivityCreated callback also gives you a savedInstanceState Bundle, which you can utilize to determine, whether the App was already running before or not.

Related