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