How to get activity link from ComponentName

I have a Foreground Screen Activity ComponentName. I can get the context object from the same. But I need an instance of activity. How to get activity link from ComponentName. All this code will be written to the service.

Thanks in advance.

+4
source share
2 answers

I will need a little more clarity about what you are trying to do, but maybe:

  • class ActivityWatcher using the onActivityStarted (or similar) method

  • to call a class that follows your view. Hierarchy

  • Keep track of the parent view and then iterate through the child views.

This will at least give you all the views from the action layout that were defined at the time the operation was created.

+1
source

You cannot get an instance of an Activity from its component name. You can save an instance of Activity as a static field in the class (when calling the onCreate Activity method) and get this field in the service.

And what do you want to do with the Activity instance in the service?

0
source

Source: https://habr.com/ru/post/1437772/


All Articles