I need to handle something in onNewIntent function, I want to do something different when current Activity is onStop or onPause status.
onStop status I mean onStop just called and activity stay on this status.
onPause status is similar.
Is there a way to check if it is onStop status or onPause status ?
seems isDestroyed() can check if onDestory is called, is there similar function for onPause and onStop ?
thanks ~
You could set a shared state variable in the onStop or onPause events.
Then retrieve it when needed.
// In your declarations:
protected static int status = 0;
// ...
@Override
protected void onPause()
{
// TODO Auto-generated method stub
super.onPause();
staus = 1;
}
@Override
protected void onStop()
{
// TODO Auto-generated method stub
super.onStop();
staus = 2;
}
// Then, wherever in your code (even in other activities) you can check the
// value of status. And even reset it to its initial value, 0
There is no build in function to determine in which state an Activity is. If you really need that you can use a flag to indicate in which state the Activity is or have a look here for a better solution.
Use this in your activity class it will help you
@Override
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
Toast.makeText(getApplicationContext(), "On Pause", Toast.LENGTH_SHORT).show();
// write code whatever you want to write here
}
@Override
protected void onStop() {
// TODO Auto-generated method stub
super.onStop();
Toast.makeText(getApplicationContext(), "On Stop", Toast.LENGTH_SHORT).show();
// write code whatever you want to write here
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.