2012-08-10 57 views

回答

1

onUserLeaveHint()

調用作爲活動週期的一部分,當活動即將 去到後臺,成爲用戶選擇的結果。例如,當 用戶按Home鍵時,onUserLeaveHint()將被調用,但 當來電呼叫導致呼叫中的Activity被自動帶到前臺 時,onUserLeaveHint()將不會被呼叫 活動被中斷。在被調用的情況下, 在活動的onPause()回調之前調用此方法。

使布爾變量真內onUserLeaveHint()爲:

@Override 
    public void onUserLeaveHint() { 
       super.onUserLeaveHint(); 
       //make Boolean true here because this method first 
       //called when user press home key 
      } 
1

你需要重寫附加於窗的方法。 請檢查以下代碼。

@Override 
public void onAttachedToWindow() { 
this.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD); 
super.onAttachedToWindow(); 
//set your boolean value here 
}