The name of the operation or recipient calling the service

I have an Intent service that is called either from a recipient or due to an action. I would like to know the name of the recipient or the activity that starts the service. I do not want to use any additional functions or flags to pass to the service.

Is there a way to see the activity stack while the code is in startup?

+4
source share
2 answers

As far as I know, there is no way to detect the sender of the intent.

+5
source

Is there a way to see the activity stack while the code is in startup?

You can use ActivityManager.RunningTaskInfo . Although it does not provide many APIs, it is probably sufficient for your requirements. Pseudocode:

ActivityManager activityManager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE); List<ActivityManager.RunningTaskInfo> runningTasks = activityManager.getRunningTasks(10); ActivityManager.RunningTaskInfo firstTask = runningTasks.get(0); String topActivityName = firstTask.topActivity.getShortClassName(); String rootActivityName = firstTask.baseActivity.getShortClassName(); 

It gives you the ability to extract the top and root operations of a specific task (AKA. Back stack). Please note: you need to set persimmon GET_TASKS to AndroidManifest.xml.

0
source

All Articles