我有一個應用程序從AlarmManager
接收廣播。在此之後,它開始透明Activity
(AlarmAlertDialogActivity
),然後顯示AlertDialog
。點擊取消AlertDialog
導致致電finish()
。要使用哪種Android意圖標誌
由於AlarmAlertDialogActivity
不是從另一個Activity
推出,但廣播接收器,它與
Intent.FLAG_ACTIVITY_NEW_TASK
推出這意味着該活動將在一個新的任務展開。
我的問題是,當取消AlertDialog
後(即通過按住home按鈕並單擊應用程序的圖標)重新啓動應用程序時,AlertDialog將重新啓動。我希望通過使用finish()
/Intent
標誌,我將能夠避免這種情況;我想要發生的是最後Activity
之前AlertDialog
的父活動將啓動。
我試過掩碼Intent.FLAG_ACTIVITY_NO_HISTORY
作爲附加標誌啓動時AlarmAlertDialogActivity
但這似乎沒有什麼區別。
位掩碼Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS
的作品,但只有從最近的歷史(如名稱暗示)刪除應用程序。這對用戶體驗是不利的。
那麼,是否有可能獲得我期待的UI流?
UPDATE - 如要求提供更多信息:
05-30 10:36:00.132: D/everyOtherApp(362): Received alarm broadcast at: Wed May 30 10:36:00 GMT+00:00 2012
05-30 10:36:00.262: D/everyOtherApp(362): AlarmAlertDialogActivity.onCreate()
05-30 10:36:00.912: D/everyOtherApp(362): AlarmAlertDialogActivity.onResume()
05-30 10:36:12.461: D/everyOtherApp(362): Cancel pressed
//Cancel exits the activity. I now relaunch the app from recent history:
05-30 10:36:20.233: D/everyOtherApp(362): AlarmAlertDialogActivity.onCreate()
05-30 10:36:21.621: D/everyOtherApp(362): AlarmAlertDialogActivity.onResume()
代碼從廣播接收器發射活動:
Intent intent = new Intent(new Intent(applicationContext, AlarmAlertDialogActivity.class));
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.putExtra(Constants.SCHEDULED_ALARM_TAG, alarm);
applicationContext.startActivity(intent);
從廣播接收器,在AlertDialog活動,我的主要活動
logcat的
manfest文件中的AlarmAlertDialogActivity:
<activity
android:name=".AlarmAlertDialogActivity"
android:theme="@android:style/Theme.NoDisplay" >
</activity>
**「此後,它開始一個透明的活動......」** - 不要這樣做!我不是指*透明*部分,我的意思是沒有'警報'觸發侵入式UI對象(AlertDialog)。通過一切手段使用將出現在狀態欄中的「通知」,但不會中斷用戶可能正在做的任何事情。 – Squonk
@MisterSquonk是的,我意識到這一點。該應用程序目前處於alpha階段,我打算完全刪除侵入式對話框或將其設爲非默認用戶選項,但我想知道是否有辦法做到我想要的。 – barry
我不知道是否有辦法做到這一點,因爲它不是我曾經考慮過的事情。如果這是'阿爾法'編碼,那麼,對我而言,如果你打算將其刪除,似乎你正在浪費你的時間和精力。即使是「可選」,也意味着任何發現它侵入的人都會禁用它。我所說的只是退後一步,重新思考這應該達到的目標,並考慮一種更適合用戶體驗的方法。 – Squonk