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

查看:111
本文介绍了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条目提供了当前显示的活动...至少在我已启动的棉花糖设备上.这给了我我所需要的.

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天全站免登陆