android notification回传数据(返回数据)
来源:互联网 发布:西门子840d编程指令 编辑:程序博客网 时间:2024/05/18 06:24
在我们写程序的时候有时候会用到notification把通知做到通知栏。当点击通知栏的时候还需要回传数据到目标activity。那么当点击的时候打开你的那个页面会出现一些问题。那就是当这个页面在后台运行时,系统还是会创建一个新的activity。为了不让activity实例化多次,我们在mainfest中的对应activity会加android:launchMode="singleTask"。那这个时候activity就不会走onCreate()等其他生命周期,而是走onNewIntent();
@Overrideprotected void onNewIntent(Intent intent) {super.onNewIntent(intent);if(intent.hasExtra("fromNotificationBar")){ }}
不要忘记,系统可能会随时杀掉后台运行的Activity,如果这一切发生,那么系统就会调用onCreate方法,而不调用onNewIntent方法,一个好的解决方法就是在onCreate和onNewIntent方法中调用同一个处理数据的方法。
@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);Intent intent = this.getIntent();if(intent.hasExtra("fromNotificationBar")) {}}这是我在做notification的时候遇到的问题。当然在两个activity之间相互打开的时候也是同样的道理。
0 0
- android notification回传数据(返回数据)
- android 关于Notification传递数据问题
- android Intent返回数据,回调数据,startActivityForResult用法
- android利用ksoap2返回复杂数据,数据集(dataset)
- android 启动子活动返回数据
- Android 从Activity返回数据
- 接口回调(数据返回)
- 数据返回
- activity数据回传过程(返回数据给上一个活动)
- Android学习之路(八)之 Activity数据返回
- Java Web服务器向Android客户端返回数据(服务器端)
- android 网络请求获得返回数据(1)
- Android学习笔记(3)-返回数据给上一个活动
- 【实战】android获取天气情况(Json来返回数据)
- Android Webservices 返回多行多列数据(Dataset)
- android HttpURLConnection 连接网络 读取返回数据
- android 手机拍照 返回数据为空!!!!
- 【Android 开发】:从Activity中返回数据
- WPF自定义路由事件
- 并发编程--资源并发访问信号量
- 恨不该打一泰国女生的PP
- 单链表的基本操作
- 藤志萄裙奶绕暗崖辣移丈员燃缸靥
- android notification回传数据(返回数据)
- 自定义字体
- 我开博客了,我的女儿上小学了
- NFS umount 提示 device is busy
- Unable to resolve superclass 解决措施
- hdu 4333(扩展KMP)
- fragment的onCreateOptionMenu()
- LeetCode 63 Minimum Path Sum
- 新浪微博ios客户端 开发流程