Android的检测是什么导致的onPause [英] Android Detect what caused the onPause
问题描述
我不知道是否有这样做的更好的办法,但我想检测某种程度上是什么原因导致应用程序暂停。
I am not sure if there is a better way of doing this but I want to detect somehow what caused the application to pause.
在显示一个跟踪映射,如果用户单击后退或家里,我想停下来的GPS,但如果屏幕熄灭我想保持GPS运行我也使用唤醒锁,因此不会睡一特定活动(是的,我知道这可能应该是一个服务,但是这将是V2,我的时间不多了!)
On one particular activity that displays a tracking map if the user click back or home I want to stop GPS but if the screen goes off I want to keep the gps running I am also using a wake lock so it doesn't sleep (yes I know this probably should be in a service, but that will be v2 I'm running out of time!)
我重写时,后退按钮是pssed $ P $
I am overriding when the back button is pressed
@Override
public void onBackPressed() {
wl.release();
this.mMyLocationOverlay.disableMyLocation();
this.mMyLocationOverlay.disableCompass();
if (mLocManager != null) {
mLocManager.removeUpdates(mLocListener);
}
super.onBackPressed();
}
但我找不到做同样产品的一种方式。
but I can't find a way of doing the same for home.
谁能帮助?
贝克斯
推荐答案
在的onPause()
您可以致电 isFinishing()
知道是否该活动是为完成任何可能的原因还是仅仅让暂停。查看文档<一href="http://developer.android.com/reference/android/app/Activity.html#isFinishing%28%29">here
in the onPause()
you can call isFinishing()
to know if the activity is finishing for whatever may be the reason or simply getting paused. See the doc here
这篇关于Android的检测是什么导致的onPause的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!