Android:启动任何活动以在后台启动吗?

编程入门 行业动态 更新时间:2024-10-07 20:27:49
本文介绍了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:启动任何活动以在后台启动吗?

本文发布于:2023-11-05 10:21:26,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1560571.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:后台   Android

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!