[英]Android bring App back to foreground
I am devloping an app that has to work in the background and come back up when I get an event from some server. 我正在开发一个必须在后台运行的应用程序,当我从某个服务器收到事件时会重新启动该应用程序。
For that I have a Service that runs in the background and gets messages. 为此,我有一个在后台运行并获取消息的服务。 What I tought I could do was just start the Activity. 我能做的就是开始活动。 Like this: 像这样:
Intent ROA = new Intent(MainActivity.getInstance(), RouteOverviewActivity.class);
MainActivity.getInstance().startActivity(ROA);
The problem is this. 问题是这样的。 The code gets executed but the app is not pushed in the foreground. 代码被执行,但是应用未在前台推送。 When I reopen the app by hand, it opens at the activity I started in the background. 当我手动重新打开该应用程序时,它将在后台启动的活动中打开。
So everything works exept that the app is pushed to the foreground. 因此,一切正常,将应用程序推送到前台。
Thanks for your help. 谢谢你的帮助。
You should probably use your service as the context to start the activity, ie from inside your service code: 您可能应该将服务用作上下文来启动活动,即从服务代码内部:
Intent ROA = new Intent(this, RouteOverviewActivity.class);
startActivity(ROA);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.