Reputation: 180
I have the ComponentName of a foreground screen activity. I am able to get the context object from the same. But I need the activity instance. How can I get the activity reference from the ComponentName. All this code will be written in a service.
Thanks in advance.
Upvotes: 8
Views: 4845
Reputation: 3425
I'd need a little more clarity on what your attempting to do, but possibly a:
class ActivityWatcher
using the onActivityStarted
method (or similar)
to call a class that watches your view Hierarchy
This would at least give you all the views from the activities layout that are defined at the time the activity is instantiated.
Upvotes: 0
Reputation: 14022
You can not get Activity instance from it's component name.You can store Activity instance as static field in a class(when onCreate method of Activity invoked) and get that field in service.
Also what do you want to do with instance of Activity in a Service?
Upvotes: 3