2015-11-07 23 views
2

click the lower notification to open the dialog activity當打開對話框活動,發起活動始終低於如果顯示在堆棧

if launcher activity is in the stack it will appear below the dialog

if launcher activity is not in the stack the dialog will appear alone, which is what I want.

我寫的,可以點擊通知時,像圖片1觸發對話活動。但是,如果啓動器活動位於堆棧中,它將出現在對話框的下方,就像圖片2一樣。如果沒有,對話框活動將單獨顯示,這是我想要的,如圖片3。 有人能告訴我爲什麼嗎?

對話活動採用像下面的自定義樣式:

<style name="DialogTransparent" parent="Theme.AppCompat.Light.Dialog"> 
    <item name="windowNoTitle">true</item> 
</style> 

,下面將通知製造商代碼:

NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this).setAutoCancel(false).setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.todo_logo)).setSmallIcon(getNotificationIcon()).setContentText(getString(R.string.notificatioin_new_task)).setOngoing(true); 
Intent alarmIntent = new Intent(this, DialogEventActivity.class); 
PendingIntent alarmPendingIntent = PendingIntent.getActivity(this, 0, alarmIntent, PendingIntent.FLAG_UPDATE_CURRENT); 
mBuilder.setContentIntent(alarmPendingIntent); 
manager.notify(NEW_NOTIFICATION_ID, mBuilder.build()); 

我覺得活動的代碼是無關的,對嗎?

+0

你真的需要張貼您的相關代碼。 –

+0

@Yvette發佈。對不起,我的疏忽...... – Cheng

+0

沒關係,你可以將你的啓動器活動的可見性設置爲消失。 –

回答

0

如果從活動A到活動B,而B是DialogActivity的子類,或者它的主題設置爲對話框,則B將在A之前顯示爲對話框,A也可見,如果您的應用程序不在前臺並且您開始活動B,它將把你的整個應用程序放在前臺,將所有活動放在你的應用程序中。當你的應用程序在同一時間可見時,使用你的活動B和最後一次可見活動。

所以要實現您的目標,您應該讓您的Activity B作爲普通活動,而不是DialogActivity的子類,並將此活動的佈局背景設置爲透明並將您的contentView設置在屏幕中心。

+0

還有別的辦法嗎?像禁止A顯示... – Cheng

+0

我認爲你可以嘗試啓動B標誌FLAG_ACTIVITY_NEW_TASK或FLAG_ACTIVITY_CLEAR_TASK。 – starkshang

+0

不起作用... – Cheng

相關問題