我創建了一個BootReceiver,它創建一個新的活動並彈出一個警報對話框。 按下確定/取消後,該活動仍未完全關閉。我可以在Window List按鈕中看到相同的結果&我可以從Window列表中看到Alert對話框。Activity Still Runs - Android
任何想法可能是錯誤的?
我的代碼如下所示,調用完成後確定/取消buttoon保護無效onCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceState);
WindowManager.LayoutParams winParams;
getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
// Windows Attributes
requestWindowFeature(Window.FEATURE_NO_TITLE);
winParams = getWindow().getAttributes();
winParams.flags |= (WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
| WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);
getWindow().setAttributes(winParams);
// Show Popup
popup = new AlertDialog.Builder(this)
.setCancelable(true)
.setPositiveButton("agree", new OnClickListener() {
public void onClick(DialogInterface dialog, int arg1) {
if(DEBUG) Log.d(LOG_TAG, " AGREE CLICKED" );
finish();}})
.setNegativeButton("disagree", new OnClickListener() {
public void onClick(DialogInterface dialog, int arg1) {
if(DEBUG) Log.d(LOG_TAG, " DISAGREE CLICKED" );
finish();}})
.setOnCancelListener(
new DialogInterface.OnCancelListener() {
public void onCancel(DialogInterface dialog) {
finish();
}});
popup.setIcon(android.R.drawable.ic_dialog_alert);
popup.setTitle("title");
popup.setMessage("Message");
dialog = popup.create();
winParams = dialog.getWindow().getAttributes();
winParams.flags |= (WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
| WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);
dialog.getWindow().setAttributes(winParams);
dialog.setOnDismissListener(AlwaysReqWhenPS);
dialog.setOnKeyListener(this);
dialog.show();
}
protected void onStop() {
if(DEBUG) Log.d(LOG_TAG, " OnStop Called" );
super.onStop();
}
public void onDestroy() {
if(DEBUG) Log.d(LOG_TAG, " onDestroy Called" );
super.onDestroy();
}
public void onPause() {
if(DEBUG) Log.d(LOG_TAG, " onPause Called" );
super.onPause();
}
你是什麼意思的窗口列表按鈕。?警報對話框中的確定/取消按鈕如何操作活動? – Gopinath 2011-02-11 06:40:42
您不應該在啓動時啓動活動。這很令人沮喪,並顯着降低了啓動過程。 – Falmarri 2011-02-11 06:45:16