Kirill Kulakov
Kirill Kulakov

Reputation: 10245

Android logging Application launch intent logging

Is there a way to get the Intent, or any other information about how the app was launched (BroadcastReceiver,Service,Activity), within the Application, without adding code to all the class that can lunch the app (keep in mind that there are library class that I can't override.

I couldn't find anything within the Context interface, that could retrieve any data about that. I thought about using a class loader, and query somehow what classes have been loaded to memory.

Upvotes: 0

Views: 616

Answers (1)

CommonsWare
CommonsWare

Reputation: 1007296

Is there a way to get the Intent, or any other information about how the app was lunched (BroadcastReceiver,Service,Activity), within the Application, without adding code to all the class that can lunch the app (keep in mind that there are library class that I cant override.

On API Level 14+, your Application can call registerActivityLifecycleCallbacks(), after which it will be called for all lifecycle methods on activities within your app. Using that, you can call getIntent() on the Activity that is supplied to your callback.

However:

  • That is only for API Level 14+

  • That is only for activities, not other components

  • Since onNewIntent() is not included in the callbacks, you can only readily get the original Intent that started the activity, not any Intent that caused an existing instance to come back to the foreground, if that matters

Upvotes: 1

Related Questions