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.
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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With