android 区分广播、计划作业或单击活动屏幕启动应用程序

ergxz8rk  于 2022-12-09  发布在  Android
关注(0)|答案(1)|浏览(131)

Context:
We have created an application which can be started by any of the following operations:

  1. When we click on the Application's icon.
  2. When we receive a broadcast that is listened by our Application.
  3. Deeplink of any activity of our Application.
  4. The activity Screens are exposed outside of application too, like widgets, clicking on any of the activity screens.
  5. 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 activity, 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
4c8rllxm

4c8rllxm1#

1.使用putExtra()方法放置来自启动Intent的额外信息,并分别使用getIntent()onStart()获取Activity和服务的值。您可以在putExtra()方法中传递启动Activity的名称。在接收Activity/服务中,将从Intent接收到的值附加接收器类名,并将其存储在本地或远程。您必须检查所有类中的Intent值。

1.使用Google Analytics记录事件。

相关问题