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

标题: [解决] Use putExtra to pass Object value for PendingIntent Activity [打印本页]

作者: 资讯王    时间: 2014-4-13 17:06
标题: [解决] Use putExtra to pass Object value for PendingIntent Activity
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");
复制代码





欢迎光临 大马资讯论坛 - 马来西亚中文资讯平台 (http://freeinfo.com.my/) Powered by Discuz! X3.3