zoukankan      html  css  js  c++  java
  • 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设置为更新当前


  • 相关阅读:
    轻松自动化---selenium-webdriver(python) (八)
    Ubuntu 18.04 LTS 启用 WakeOnLAN
    lower_bound 和 upper_bound
    [LeetCode 201.] Bitwise AND of Numbers Range
    [LeetCode 162.] Find Peak Element
    [LeetCode 33. 81. 153. 154.] 旋转数组中的二分查找
    C++ unordered_map 的一个疑问
    [LintCode 386.] 最多有k个不同字符的最长子字符串
    [LintCode 550.] 最常使用的K个单词II
    [LintCode 1029.] 寻找最便宜的航行旅途(最多经过k个中转站)
  • 原文地址:https://www.cnblogs.com/shaoke123/p/4468487.html
Copyright © 2011-2022 走看看