博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Android_清除/更新Bundle中的数据(不finish() Activity的情况下)
阅读量:4693 次
发布时间:2019-06-09

本文共 3122 字,大约阅读时间需要 10 分钟。

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_CURRENTAdded in API level 3Flag 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_SHOTAdded in API level 1Flag 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,一身轻松!

转载于:https://www.cnblogs.com/iplus/archive/2012/11/08/4467366.html

你可能感兴趣的文章
黑马程序员 ExecuteReader执行查询
查看>>
记一些从数学和程序设计中体会到的思想
查看>>
题目1462:两船载物问题
查看>>
POJ 2378 Tree Cutting(树形DP,水)
查看>>
第二冲刺阶段个人博客5
查看>>
UVA 116 Unidirectional TSP (白书dp)
查看>>
第三方测速工具
查看>>
MySQL 网络访问连接
查看>>
在aws ec2上使用root用户登录
查看>>
数据访问 投票习题
查看>>
CIO知识储备
查看>>
cnblog!i'm coming!
查看>>
使用点符号代替溢出的文本
查看>>
Axios 中文说明
查看>>
fatal: remote origin already exists.
查看>>
gridview 自定义value值
查看>>
2018二月实现计划成果及其三月规划
查看>>
类名.class和getClass()区别
查看>>
12/17面试题
查看>>
LeetCode 242. Valid Anagram
查看>>