2015-11-07 44 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