onNewIntent()的使用
来源:互联网 发布:centos7修改远程端口 编辑:程序博客网 时间:2024/06/06 20:21
我对 onNewIntent
的理解
当我们由于某些原因,可能会反复启动一个
Activity
时,你可能会想不就是通过startActivity(intent)
,来启动嘛,反复走onCreate
就是了。但是,这样的话岂不是要反复的画布局,造成内存的浪费。其实,我们关心的是intent
到底怎么走,因为它携带了我们想要的信息。事实上,当启动一个已经启动的Activity
时,intent
会传递到onNewIntent(intent)
中,这个时候到该方法下取出intent
中存储的数据即可。
高能预警:官方说明
onNewIntent(Intent intent)
参数:
intent
Intent
: The new intent that was started for the activity.一个Activity
(此时作为对象)中,可以存在很多个intent
.
This is called for activities that set launchMode to “singleTop” in their package, or if a client used the FLAG_ACTIVITY_SINGLE_TOP flag when calling startActivity(Intent). In either case, when the activity is re-launched while at the top of the activity stack instead of a new instance of the activity being started, onNewIntent() will be called on the existing instance with the Intent that was used to re-launch it.在清单文件中设置启动模式 LaunchMode
,或者是 intent
本身添加了 FLAG_ACTIVITY_SINGLE_TOP
才会调用此方法。
An activity will always be paused before receiving a new intent, so you can count on onResume() being called after this method.
Note that getIntent() still returns the original Intent. You can use setIntent(Intent) to update it to this new Intent.通过 setIntent(Intent intent)
把传来的 intent
设置成 ·original Intent`.
Permissions
When starting an Activity you can set Intent.FLAG_GRANT_READ_URI_PERMISSION and/or Intent.FLAG_GRANT_WRITE_URI_PERMISSION on the Intent. This will grant the Activity access to the specific URIs in the Intent. Access will remain until the Activity has finished (it will remain across the hosting process being killed and other temporary destruction). As of GINGERBREAD, if the Activity was already created and a new Intent is being delivered to onNewIntent(Intent), any newly granted URI permissions will be added to the existing ones it holds.
getReferrer() 它的返回值是
Uri
If called while inside the handling of onNewIntent(Intent), this function will return the referrer that submitted that new intent to the activity. Otherwise, it always returns the referrer of the original Intent.通过这句话,可以看出来,每次 startActivity(intent)
, 都会传递一个新的 intent
.
- Android:onNewIntent的使用
- 关于onNewIntent的使用
- 关于onNewIntent的使用
- onnewintent的使用时机
- 关于onNewIntent的使用
- 关于onNewIntent的使用
- 关于onNewIntent的使用
- onNewIntent()的使用
- onNewIntent()的使用
- Activity生命周期 onNewIntent的使用
- Activity中onNewIntent的使用
- Activity生命周期 onNewIntent的使用
- onNewIntent使用遇到的坑
- 关于onNewIntent的使用&PendingIntent flag赋值
- Android:onNewIntent()的使用及注意事项
- Activity传值之onNewIntent的使用
- android onNewIntent使用详解
- Android onNewIntent()使用
- Java8中的日期与时间处理
- redis 中文存储乱码问题
- 二叉排序树
- mysql 查询次日留存 三日留存 七日留存
- Intent(意图)---纯小白自己声明给自己的---勿喷
- onNewIntent()的使用
- mapreduce提交job源码分析
- C#内存泄漏实战
- MySQL防止重复插入唯一限制的数据 4种方法
- 数据结构之排序算法
- NYOJ-236
- 对数组进行冒泡排序,使用comparable接口实现
- 1076. Forwards on Weibo (30)
- UVA 1630 Folding——区间DP(记忆化搜索)