大马资讯论坛 - 马来西亚中文资讯平台

 找回密码
 注册
搜索
打印 上一主题 下一主题

[解决] Use putExtra to pass Object value for PendingIntent Activity

[复制链接]
跳转到指定楼层
1#
发表于 2014-4-13 17:06:32 | 只看该作者 回帖奖励 |正序浏览 |阅读模式
Android - Use putExtra to pass Object value for PendingIntent Notification Activity
把object传到另个Activity form

1. Add implements Serializable in your class
  1. public class Article implements Serializable { }
复制代码
2. Create object for passing
  1. Intent notificationIntent = new Intent(this,NotifyMessage.class);
  2.             Article oArticle = new Article();
  3.             oArticle.title = splited[0];
  4.             oArticle.url = splited[1];
  5.             notificationIntent.putExtra("Msg",oArticle);  

  6. //For Notification
  7.         PendingIntent oPendingIntent =PendingIntent.getActivity(this, 0,
  8.                         notificationIntent,
  9.                         PendingIntent.FLAG_UPDATE_CURRENT);
复制代码
2. Get object when opening the activity
  1. Article ArticleObject=(Article)getIntent().getSerializableExtra("Msg");
复制代码

手机版|大马资讯论坛  

GMT+8, 2024-12-5 11:38 , Processed in 0.016190 second(s), 12 queries , File On.

Powered by Discuz! X3.3

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表