zoukankan      html  css  js  c++  java
  • Android_清除/更新Bundle中的数据(不finish() Activity的情况下)

    LZ:跪求清空bundle中数据的方法!!!!!!!!!!!!可怜

    -------------------------------------------------------------------------------------------------

    http://www.cnblogs.com/lilihuang/archive/2011/05/12/2044668.html        //谷哥度娘都说这个好,finish(),就是这么排毒养颜!!!

    ------------------------------------------------------------------------------------------------

    LZ:谢谢楼上大大,但是我的activity还没活够,暂时还不能被finish()呢,继续冰天雪地跪求更好办法。可怜

    -------------------------------------------------------------------------------------------------

    bundle.remove("A");    //楼主太弱了,吃奶去吧鄙视

    -------------------------------------------------------------------------------------------------

    bundle.clear();           //一楼测试过了吗?totally不行也,看我正统clear()杀将过来

    --------------------------------------------------------------------------------------------------

    bundle = null;           //小弟补充下,经测试,同样不行,求解!

    ---------------------------------------------------------------------------------------------------

    clearCache();                                  //网上有http://bbs.csdn.net/topics/220044021,但是得自己实现,bundle是存在于Parcle包之上?而大家都知道Parcel包是需要recycle()进行更新的,难道是BUG?

    thisActivity.deleteDatabase();      //接口是有,但是本程序没有用到数据库啊!

    System.gc();                                    //这是搞哪样,gc接口都上了;抓狂

    //看来问题严重了,引起重视,继续求解委屈

    ---------------------------------------------------------------------------------------------------

      getIntent().removeExtra();                //楼上众DS请让道,

    //咦,这下更惨了,“A”都取不到了;匿了,我吃奶去!

    ---------------------------------------------------------------------------------------------------


    当当当当,哥闪电出场:

    intent.setFlags(PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_ONE_SHOT);
    其实是从这里瞄到的:

    http://stackoverflow.com/questions/4116110/android-clear-intent

    http://stackoverflow.com/questions/3168484/pendingintent-works-correctly-for-the-first-notification-but-incorrectly-for-the


    仔细看看android doc就知道原因了:

    FROM: http://developer.android.com/reference/android/app/PendingIntent.html#FLAG_UPDATE_CURRENT

    public static final int FLAG_UPDATE_CURRENT
    
    
    Added in API level 3
    Flag for use with getActivity(Context, int, Intent, int), getBroadcast(Context, int, Intent, int), 
    and getService(Context, int, Intent, int): if the described PendingIntent already exists, 
    then keep it but its replace its extra data with what is in this new Intent. 
    This can be used if you are creating intents where only the extras change, 
    and don't care that any entities that received your previous PendingIntent will be able to launch it with your new extras even if 
    they are not explicitly given to it.
    
    
    Constant Value: 134217728 (0x08000000)
    &

    public static final int FLAG_ONE_SHOT
    
    
    Added in API level 1
    Flag for use with getActivity(Context, int, Intent, int), getBroadcast(Context, int, Intent, int), 
    and getService(Context, int, Intent, int): this PendingIntent can only be used once. 
    If set, after send() is called on it, 
    it will be automatically canceled for you and any future attempt to send through it will fail.
    
    Constant Value: 1073741824 (0x40000000)


    我们用到PendingIntent的FLAG属性,至于Intent与PendingIntent的区别,这位仁兄已经讲解得非常明白:

    http://blog.csdn.net/zeng622peng/article/details/6180190

    但我们在这里没未用到PendingIntent的对象,只是借用了其FLAG而已。看来stackoverflow实乃居家旅行,杀虫必备啊!


    好了,这下妈妈再也不用担心我的bundle更新啦!排除BUG,一身轻松!

    Meet so Meet. C plusplus I-PLUS....
  • 相关阅读:
    如何随机生成指定数目的国标汉字?
    动态裁剪窗体标题栏
    N皇后问题
    谈谈五皇后问题
    一道趣味数学题
    In version 2.0, DB Query Analyzer will never be mistaken as virus by antivirus software
    从2.0版本开始,“万能数据库查询分析器”的中英文版本不再被误报成病毒
    Android_获取屏幕大小的两种方法
    广东电信公话201亲情月卡用户重复购买率模型的研究
    基于关系数据库的数据仓库星形模式下维使用原则的研究与探索
  • 原文地址:https://www.cnblogs.com/iplus/p/4467366.html
Copyright © 2011-2022 走看看