android Notification 通知栏点击不能跳转(转自:http://www.oschina.net/question/778954_212394)...

roid Notification 通知栏点击不能跳转


关于通知栏Notification的使用,不多讲,这里说的很清楚http://www.cnblogs.com/zenfly/archive/2012/02/09/2343923.html

先说下我遇到的问题:

在应用关闭的时候,发送通知到通知栏,点击通知栏能正常跳转到我想要的页面,代码如下

1 Intent msgIntent =  new Intent();
2  
3 msgIntent.addCategory(Intent.CATEGORY_LAUNCHER);
4                         msgIntent.setComponent( new ComponentName(context.getPackageName(), "com.test.FragmentActivity"));
5  
6 msgIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); //  关键的一步,设置启动模式
7   
8 UITools.showNotification(context, Notify.NORMAL, msgIntent, jsonBean.getMessageTitle());

在应用打开的情况下,发送通知,代码如下: 

1 Intent msgIntent =  new Intent();
2  
3 msgIntent.setClass(context, FragmentActivity. class);
4  
5 msgIntent.setFlags(Intent.FLAG_ACTIVITY_MULTIPLE_TASK | Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); //  关键的一步,设置启动模式
6   
7 UITools.showNotification(context, Notify.NORMAL, msgIntent, jsonBean.getMessageTitle());



以上这段代码,出现了不能跳转的情况,于是,做了如下操作解决上述问题

1  < activity
2               android:name =".activity.FragmentActivity"
3              android:taskAffinity =""   >
4          </ activity >

设置栈,可以正常响应我的通知栏意图了,但是新的问题出现了,当我按下Home键回到桌面的时候,在回来,就不能打开按下之间的页面了,不同的栈,,,,,

-------问题总是有的,于是换了一种折中的解决方案

1 Intent msgIntent =  new Intent();
2  
3 msgIntent.setAction(IntentAction.ACTION_TRIP_APPROVE);
4  
5 UITools.showNotificationBroadcast(context, Notify.NORMAL, msgIntent, jsonBean.getMessageTitle());   // 这里是发送广播哦


设置通知栏的意图为发送广播

    
PendingIntent pendingIntent = PendingIntent.getBroadcast( this, count, intent, PendingIntent.FLAG_UPDATE_CURRENT);



当然,这带来了新的问题,如果我的通知栏需要传递参数怎么办,可以通过如下方式传递

intent.setData(Uri.parse("abc"));



这种可以传递结构化的数据,那我们所谓的bundle就不能使用了么,当然不是,如下

1 PendingIntent pendingIntent = PendingIntent.getBroadcast( this, requestCode, intent, PendingIntent.FLAG_UPDATE_CURRENT);
2 PendingIntent pendingIntent = PendingIntent.getBroadcast( this, requestCode, intent, PendingIntent.FLAG_UPDATE_CURRENT);

标红的地方是重点,为每个意图设置不同的requestCode,Flag设置为更新当前


转载于:https://www.cnblogs.com/shaoke123/p/4468487.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值