简体   繁体   English

Android将应用重新带到前台

[英]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.

相关问题 Android-将应用程序移至后台并移至前景时不维护后退堆栈 - Android - Back stack is not maintained when app is moved to background and bring to foreground 如何启动另一个应用或使其像Android启动器一样回到前台? - How to launch another app or bring it back to foreground like Android launcher? 将正在运行的Android应用程序带到前台 - Bring A Running Android App to Foreground 设备休眠时将Android应用置于前台 - Bring Android app to foreground when device is sleeping 如何将Android应用程序在后台运行到前台 - Ways to bring an Android app in background to foreground 如何在Calabash-android中将应用程序带到Foreground? - How to bring app to Foreground in calabash-android? Android 在 Firebase 通知上将应用程序带到前台 - Android bring app to foreground on Firebase notification GPS位置更改时如何将Android应用程序带回前台 - How to bring back an Android application to foreground when GPS location is changed 如何将监视光传感器的背景安卓应用程序带到前景 - How to bring background android app which monitors light sensor to foreground 将FCM通知中的Android应用的前一个实例置于前台 - Bring Android app's previous instance to foreground from FCM notification
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM