Reputation: 553
I am working on an app in which I have to get all the views of the top most activity. This activity may or may not be of my app.
I am able to get all the views from a ViewGroup(root view)
.
Now I just want to get the root view of top most activity to do my work but I was not able to find any answers which gives me an idea to get root view of an activity from service.
I had used these methods:
View rootView = Window.DecorView.RootView;
and
Context ctx = this;
ViewGroup rootView = ((Activity)ctx).getWindow().getDecorView().findViewById(android.R.id.content);
But nothing works inside service class.
It reports that getWindow()
and findViewById
() did not work inside android service class.
So I just want to know is there any other way to do the same?
Thanks In Advance...:-)
Upvotes: 0
Views: 2259
Reputation: 1006539
I am working on an app in which I have to get all the views of the top most activity. This activity may or may not be of my app.
Fortunately, this is not possible, for blindingly obvious privacy and security reasons.
It's also not possible from a simple programming standpoint, as the views in whatever you think "the top most activity" is are from another process. You cannot have an object from another process in yours, by definition.
Upvotes: 1