Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the activity reference from the ComponentName

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.

like image 617
ShwetaK Avatar asked Oct 04 '12 10:10

ShwetaK


2 Answers

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?

like image 111
hasanghaforian Avatar answered Sep 24 '22 09:09

hasanghaforian


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

  • Watch the parent view and then iterate thru the child views.

This would at least give you all the views from the activities layout that are defined at the time the activity is instantiated.

like image 37
Peter Birdsall Avatar answered Sep 25 '22 09:09

Peter Birdsall