如何在不关闭先前活动的情况下从通知中打开对话框样式的活动? [英] How to open dialog styled activity from notification without previous activity closing?

查看:80
本文介绍了如何在不关闭先前活动的情况下从通知中打开对话框样式的活动?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  1. 我有一个具有对话框样式的活动,因此它在上一个活动的顶部以可视方式打开.
  2. 我有一条通知会打开此活动,如下所示:


Intent intent = new Intent(this, CalcActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
builder.setContentIntent(pendingIntent);
((NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE)).notify(0, builder.build());

问题在于,当用户点击我的通知时,先前的可见活动关闭,出现主屏幕,并且我的对话框显示在主屏幕顶部.如何防止关闭先前的活动?请注意,以前的活动可能不是来自我的应用.

The problem is that when user taps my notification, previous visible activity closes, home screen appears and my dialog is displayed on top of home screen. How to prevent closing of previous activity? Please note that previous activity might not come from my app.

推荐答案

使用Intent如下:

Use Intent as below :

Intent intent = new Intent(this,MainActivity.class).setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

并在AndroidManifest.xml中注册活动并将主题用作dialog:

and in AndroidManifest.xml register activity and use theme as dialog:

<activity android:name=".MainActivity" android:theme="@style/Theme.AppCompat.Light.Dialog"/>

这篇关于如何在不关闭先前活动的情况下从通知中打开对话框样式的活动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆