Android:启动任何活动以在后台启动? [英] Android: launch any activity to start in the background?

查看:35
本文介绍了Android:启动任何活动以在后台启动?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我正在编写自己的 Android 应用程序,我知道如何将其构建为服务,以便它开始在后台运行.

If I'm writing my own Android app, I know how to structure it as a Service so it will start running in the background.

但是,有没有办法启动现有应用(例如,来自 Play 商店的任何随机 .apk),使其在后台启动,而其屏幕不会接管显示?

However, is there a way to launch an existing app (for example, any random .apk from the Play Store) so that it starts up in the background, without its screen taking over the display?

或者,我愿意启动应用程序,将其强制进入后台,然后重新显示在前台运行的前一个应用程序(无论它可能是什么)的窗口.我不知道如何以编程方式将当前应用程序置于后台,然后确定上一个应用程序并将其带回前台.

Alternatively, I'd be willing to launch the app, force it into the background, and redisplay the window of the previous app (whatever it might have been) that was running in the foreground. I don't know how to programmatically put the current app in the background and then determine the previous app and bring it back to the foreground.

我愿意以任何可能的方式执行此操作:通过 Java、通过一个或多个命令行实用程序、通过 Tasker 插件、通过 Xposed 模块或其他任何方式.

I'm willing to do this any way possible: via Java, via one or more command-line utilities, via a Tasker plugin, via an Xposed module, or whatever.

预先感谢您对文档的任何指示或任何建议.

Thank you in advance for any pointers to docs or any suggestions.

推荐答案

我发现dumpsys 活动最近"的 #0 条目给出了当前显示的活动......至少在我的 root 棉花糖设备上.这给了我我需要的东西.

I discovered that the #0 entry of "dumpsys activity recents" gives the currently displayed activity ... at least on my rooted Marshmallow device. This gives me what I need.

这篇关于Android:启动任何活动以在后台启动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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