How to inform an Activity that another Activity was just started?

前端 未结 4 577
逝去的感伤
逝去的感伤 2020-12-29 17:24

I just want to get numbers of times to be used for each Activity. So the very straightforward method I thought is increasing the count for an Activity when it was started. B

4条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-29 17:55

    If you're an Android OEM developer/partner, you can use IActivityController.Stub to get what you need. You can then use ActivityManagerNative as below to start receiving events.

    ActivityManagerNative.getDefault().setActivityController(activityController);
    

    You would need to save your whitelist/blacklist preferences somewhere and compare with the package from the IActivityController.Stub callback. E.g.,

    public boolean activityStarting(Intent intent, String pkg) {
        Slog.d(AdbLogTag.TAG, "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
        Slog.i(AdbLogTag.TAG, String.format("Application starting {intent=%s}, pkg=%s", intent, pkg));
        Slog.d(AdbLogTag.TAG, "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
    

    Hope this helps.

提交回复
热议问题