Android点击通知进入详情,android – 点击通知进入当前活动

我正在使用这个解决方案:

How to make notification intent resume rather than making a new intent?

当我正常运行我的应用程序时工作正常..但是我的应用程序具有共享功能.

当我选择要从图库应用程序共享的图像并在我的活动中打开它时,我在活动中创建通知.我希望当用户点击通知时,它会打开现有活动(由图库应用打开)

问题是,当我点击通知时,它不会恢复该活动,而是打开活动的新实例或之前已打开的另一个实例

编辑:

更多解释

我的应用程序名为ShareApp,该活动称为ShareActivity

问题是当我通过gallery app打开ShareActivity时,会在gallery app任务的堆栈顶部创建一个ShareActivity实例.现在,当我创建指向我的ShareActivity的通知时,我使用了intent:

Intent intent = new Intent(this, ShareActivity.class);

intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);

intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

问题是,当我点击通知时,它指向ShareApp任务的堆栈中的ShareActivity实例,而不是gallery app任务的堆栈.

任何想法如何指向正确的任务的堆栈?

编辑2:我的代码

int defaults = Notification.FLAG_NO_CLEAR;

NotificationCompat.Builder mBuilder =

new NotificationCompat.Builder(this)

.setSmallIcon(R.drawable.ic_launcher)

.setContentTitle(getString(R.string.app_name))

.setContentText(text)

.setDefaults(defaults);

Intent intent = new Intent(this, this.getClass());

intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);

intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT);

mBuilder.setContentIntent(pendingIntent);

NotificationManager mNotificationManager =

(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

mNotificationManager.notify(_ID, mBuilder.build());

我的应用程序名为shareApp,我的活动是ShareActivity

在点击通知之前:

Main stack:

TaskRecord{41965708 #6 A com.android.gallery3d}

Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10200000 cmp=com.android.gallery3d/.app.Gallery bnds=[364,50][108,108]}

Hist #2: ActivityRecord{417ccc28 com.yeahman.shareapp/.ShareActivity}

Intent { act=android.intent.action.SEND_MULTIPLE typ=image/* cmp=com.yeahman.shareapp/.ShareActivity (has extras) }

ProcessRecord{41c868d0 6088:com.yeahman.shareapp/10116}

Hist #1: ActivityRecord{4135e540 com.android.gallery3d/.app.Gallery}

Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10200000 cmp=com.android.gallery3d/.app.Gallery bnds=[364,50][108,108] }

点击通知后:

Main stack:

TaskRecord{41965708 #6 A com.android.gallery3d}

Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10200000 cmp=com.android.gallery3d/.app.Gallery bnds=[364,50][108,108]}

Hist #3: ActivityRecord{4169f358 com.android.gallery3d/.app.Gallery}

Intent { flg=0x20000000 cmp=com.android.gallery3d/.app.Gallery bnds=[0,205][480,301] }

ProcessRecord{4175dd28 5808:com.android.gallery3d/10036}

Hist #2: ActivityRecord{417ccc28 com.yeahman.shareapp/.ShareActivity}

Intent { act=android.intent.action.SEND_MULTIPLE typ=image/* cmp=com.yeahman.shareapp/.ShareActivity (has extras) }

ProcessRecord{41c868d0 6088:com.yeahman.shareapp/10116}

Hist #1: ActivityRecord{4135e540 com.android.gallery3d/.app.Gallery}

Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10200000 cmp=com.android.gallery3d/.app.Gallery bnds=[364,50][108,108] }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值