我需要处理onNewIntent函数中的某些内容,我想在当前Activity处于onStop或onPause状态时做一些不同的事情。有没有办法检查活动是onStop状态还是onPause状态?
onStop状态我的意思是onStop只是叫,活动停留在这种状态。
onPause状态类似。
有没有办法检查它是onStop状态还是onPause状态?
似乎isDestroyed()可以检查是否onDestory被调用,是否有onPause和onStop类似的函数?
谢谢〜
我需要处理onNewIntent函数中的某些内容,我想在当前Activity处于onStop或onPause状态时做一些不同的事情。有没有办法检查活动是onStop状态还是onPause状态?
onStop状态我的意思是onStop只是叫,活动停留在这种状态。
onPause状态类似。
有没有办法检查它是onStop状态还是onPause状态?
似乎isDestroyed()可以检查是否onDestory被调用,是否有onPause和onStop类似的函数?
谢谢〜
您可以在onStop或onPause事件中设置共享状态变量。
然后在需要时检索它。
// 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
没有构建函数来确定活动在哪个状态。如果您真的需要这样做,您可以使用标志来指示活动是在哪个状态下进行的,或者看看here以获得更好的解决方案。
使用此在活动类它会帮助你
@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
}
我不想在onPause和onStop回调中做这些事情,我只想检查当前活动是否处于这种状态。 – zhibin
你想知道你的活动是暂停还是其他? –
看来这是一种解决方法,它不能是静态变量,因为多个实例将共享。 还认为这不是一个好的解决方案,因为保持这个变量值是不容易的(也需要在onResume,onStart,onRestart,onDestory和其他地方设置这个值)。 – zhibin