Is there a way to know who is the application caller?
These are several use cases cases:
- I have an application and a widget of it. Application is not running. Once I add/remove the widget, the system calls the application to run (
Application.onCreate()is called and etc..). So I need to know that this is not a user who press an icon to run application, but this is a system needs to update widget. - When I get low of memory, the system kills the application and then restors it again when there is enough memory. The question is the same as above.
- More similar cases…
The only case that I can manage is a BootUpReceiver which is extended from BroadcastReceiver. Only in this case I am sure that the application is run by the “launch at start” feature.
I need to know for sure – who (what service, receiver, intent, etc) any why is calling my application.
Is there a way to know the caller source, or caller ID or any information about a service or any other who call my application to run?
As @CommonsWare already mentioned:
But actually you can get a general idea about why your application was called by dumping message query of
MainLooper. You can use following code to do this:You shouldn’t use this code for any “logic” in your app, but you can use it for debugging and/or logging to get a general idea about
Intents sent by system to your app to start it. You should call this method as early as possible, and in logs you will see something like this:Message N – this is a messages which was send by the system to your app. Here you will see defferent messages and this messages should give you a general idea about callers of your app.