有没有办法从服务中获取活动的根视图? [英] Is there any way to get root view of an activity from a service?

查看:27
本文介绍了有没有办法从服务中获取活动的根视图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个应用程序,我必须在其中获取最热门活动的所有视图.此活动可能属于或可能不属于我的应用.我能够从 ViewGroup(root view) 获取所有视图.现在我只想获得最重要的活动的根视图来完成我的工作,但我找不到任何答案,这让我想从服务中获取活动的根视图.

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.

我使用过这些方法:

View rootView = Window.DecorView.RootView;

Context ctx = this;
ViewGroup rootView = ((Activity)ctx).getWindow().getDecorView().findViewById(android.R.id.content);

但在服务类中没有任何作用.它报告 getWindow()findViewById() 在 android 服务类中不起作用.所以我只想知道有没有其他方法可以做到这一点?提前致谢...:-)

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...:-)

推荐答案

我正在开发一个应用程序,我必须在其中获取最热门活动的所有视图.此活动可能是也可能不是我的应用.

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.

这篇关于有没有办法从服务中获取活动的根视图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆