Context:
We have created an application which can be started by any of the following operations:
- When we click on the Application's icon.
- When we receive a broadcast that is listened by our Application.
- Deeplink of any activity of our Application.
- The activity Screens are exposed outside of application too, like widgets, clicking on any of the activity screens.
- Scheduled periodic job restarting application in case it was killed.
Use Case: I want a way to differentiate between Case 2, 5 from other case because for other 3 scenarios' we will get onCreate of some application's activity.
But for case 2 when we get a broadcast, it doesn't start any activity, it just calls some services and stores some data.
Is there a way I can identify whether this has happened or not?
Why do we want to do this? We are actually working on testing the fully drawn time (latency) of our different activities for different scenarios. For all the activities, we are starting from onCreate of the activities and closing the timer at fullyDrawn, but for the Broadcast calls, we can not identify that Application is already started.
Question: How can we differentiate if an application is started by an activity or by some broadcast or periodic jobs?
We tried adding some singleton Boolean in onCreate of Application and onCreate of Activity, using this we can identify that application is called because of ac开发者_Go百科tivity, but still this doesn't help with identifying what if Application was created earlier even before the activity's flow was triggered?
If that helps I will share some dummy code, please let me know.
Thank you
- Put the extra info from starting Intent using
putExtra()
method and get the values usinggetIntent()
&onStart()
for activity & service respectively. You can pass name of starting activity inputExtra()
method. In receiving activity/service append the received value from intent with the receiver class name and store it locally or remote. You have to check for intent values in all classes.
OR - Use Google Analytics to log events.
精彩评论