简体   繁体   English

如何查找应用程序是在后台运行还是在前台运行或被杀死的android

[英]How to find whether app is running in background or foreground or killed android

I need a suggestion from you guyzz that, In my application i am using GCM Broadcast receiver , and my app is having PIN page also. 我需要您的建议,在我的应用程序中,我使用的是GCM Broadcast Receiver ,而我的应用程序中也有PIN页 Here i need to check a condition like either user is logged in or not when ever push notification comes, depends upon i need to set different Activities . 在这里,我需要检查类似推送通知到来时用户是否登录的情况,这取决于我需要设置不同的Activity So can anybody suggest me how to solve this?? 那么有人可以建议我如何解决这个问题吗? sorry for my English. 对不起我的英语不好。

You can do as followed: 您可以执行以下操作:

When your app is not started/ running and you start from an notification, onCreate gets called. 当您的应用未启动/未运行且从通知启动时,将调用onCreate。

@Override
protected void onCreate(Bundle savedInstanceState) {
   super.onCreate(savedInstanceState);
}

When your app is running (background or foreground), and you start a new intent from an notification this method gets called: (if you are using singleTop) 当您的应用程序正在运行时(后台或前台),并且您从通知中启动新的意图时,此方法将被调用:(如果您使用的是singleTop)

@Override
protected void onNewIntent (Intent intent){

}

To detect whether your app is running back- or foreground, you can simply set a boolean in onPause/onResume: 要检测您的应用是后台运行还是前台运行,您只需在onPause / onResume中设置一个布尔值即可:

@Override
protected void onResume() {
  super.onResume();
  runningOnBackground = false;
}

@Override
protected void onPause() {
  super.onPause();
  runningOnBackground = true;
}

Hope it helps! 希望能帮助到你!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何查找应用程序是在后台运行还是被杀死的android? - How to find whether app is running in background or killed android? 如何检查应用程序是在前台还是后台 - How to check whether the app is in foreground or background 如何检查活动是在Android中的前景还是背景? - How to check whether activity is in foreground or background in android? Android如何在用户杀死应用程序后继续运行后台服务? - Android How to keep Running the background service when app is killed by user? 当 React Native Android 应用程序在后台或已被杀死时,如何将其带到前台? - How to bring a React Native Android app to the foreground when it is in the background or has been killed? “杀死”后在后台运行Android应用程序 - Running Android App in the Background after “killed” 如何检查应用程序是在后台还是前台android。 使用以下代码但无法检查 - How to check whether a app is in background or foreground android. Using following code but unable check 如何检查应用程序是否在BroadcastReceiver中的前台后台运行 - How to check app is running in background of foreground in BroadcastReceiver 我如何知道我的Android应用程序是否在后台运行? - How do I know whether or not my Android app is running in background? 如何调试在后台和前台运行的 android 应用程序 - How to debug android apps running in background and Foreground
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM