Android Intent传递对象摘要
效果:
watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvaG9uZ3NoZW5ncGVuZw==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast" alt="">
想看实例的,感兴趣的能够看之前的一篇文章
Android ViewPager Fragment实现选项卡
部分关键代码:
public class SerializeActivity extends Activity implements Serializable { Button btnlist, btnParcelable, btnSerialze;
private final String TAG = "SerializeActivity";
public final static String LIST_KEY = "ArrayList";
public final static String PAR_KEY = "parcelable";
public final static String SER_KEY = "serializable";
private static final long serialVersionUID = 1L; private ArrayList<String> m_list; @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_serialize);
initView();
initlist();
}
/*
* 初始化视图
*/
public void initView() {
btnlist = (Button) findViewById(R.id.btnlist);
btnParcelable = (Button) findViewById(R.id.btnParcelable);
btnSerialze = (Button) findViewById(R.id.btnSerialze);
btnlist.setOnClickListener(btnlistener);
btnParcelable.setOnClickListener(btnlistener);
btnSerialze.setOnClickListener(btnlistener);
}
public void initlist() { m_list = new ArrayList<String>();
m_list.add("www.88ios.com");
m_list.add("Android移动开发");
m_list.add("IOS开发入门"); }
/*
* button点击事件
*/
OnClickListener btnlistener = new OnClickListener() { public void onClick(View v) {
switch (v.getId()) {
case R.id.btnlist: intentList();
break;
case R.id.btnParcelable: intentParcelabe();
break;
case R.id.btnSerialze: intentShowSer(); break;
}
}
};
/*
*
*/
public void intentList() {
Intent list_intent = new Intent();
list_intent.putStringArrayListExtra(LIST_KEY, m_list);
list_intent.setClass(SerializeActivity.this, ShowInfo.class);
startActivity(list_intent);
}
/*
*
*/
public void intentParcelabe() {
Student m_Student = new Student();
m_Student.setName("88ios.com");
m_Student.setAge(25);
m_Student.setSex("男");
Intent p_Intent = new Intent(SerializeActivity.this,
ShowParcelabe.class);
Bundle mBundle = new Bundle();
mBundle.putParcelable(PAR_KEY, m_Student);
p_Intent.putExtras(mBundle);
startActivity(p_Intent);
}
/*
*
*/
public void intentShowSer() {
final SerializableMap myMap = new SerializableMap(); List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
Map<String, Object> maplist;
Map<String, Object> paramMap4 = new HashMap<String, Object>(); paramMap4.put("name", "洪生鹏");
paramMap4.put("website", "www.88ios.com");
paramMap4.put("address", "广州");
myMap.setMap(paramMap4); SerializableMap serializableMap = (SerializableMap) myMap;
maplist = serializableMap.getMap();
list.add(maplist); Intent mIntent = new Intent(SerializeActivity.this, ShowSer.class);
Bundle mBundle = new Bundle(); mBundle.putSerializable("map", (Serializable) myMap);
//mBundle.putSerializable("map", (Serializable) list); mIntent.putExtras(mBundle);
startActivity(mIntent);
} }
ShowInfo.java
public class ShowInfo extends Activity { private Intent list_intent;
private ArrayList<String> m_arrayList;
private TextView textview; @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_show_info); textview = (TextView) findViewById(R.id.textview);
StringBuffer sb = new StringBuffer(); list_intent = getIntent();
m_arrayList = list_intent.getExtras().getStringArrayList(
SerializeActivity.LIST_KEY);
m_arrayList.get(0); sb.append(m_arrayList.get(0) + " \n" + m_arrayList.get(1) + "\n"
+ m_arrayList.get(2)); textview.setText(sb);
} }
ShowParcelabe.java
public class ShowParcelabe extends Activity {
private TextView textview;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_show_parcelabe); textview = (TextView)findViewById(R.id.textview);
Student p_student = (Student)getIntent().getParcelableExtra(SerializeActivity.PAR_KEY);
textview.setText("姓名: " + p_student.getName()+"\n"+
"年龄: " + p_student.getAge() + "\n" +
"性别 : " + p_student.getSex() + "\n" +
"类:" + p_student.getClass());
} }
ShowSer.java
public class ShowSer extends Activity {
private TextView textview;
StringBuilder sb = new StringBuilder(); @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_show_ser);
textview = (TextView)findViewById(R.id.textview);
Map<String, Object> maplist;
Bundle bundle = getIntent().getExtras();
SerializableMap serializableMap = (SerializableMap) bundle.get("map");
maplist = serializableMap.getMap();
/*
for (String k : maplist.keySet()) {
Toast.makeText(this, "" + maplist.get(k), Toast.LENGTH_SHORT)
.show();
}
*/
Set set = maplist.entrySet();
Iterator it = set.iterator();
while (it.hasNext()) {
Map.Entry entry = (Map.Entry) it.next();
String key = (String) entry.getKey();
String valu = (String) entry.getValue();
sb.append(key+" "+valu+"\n");
}
textview.setText(sb);
} }
转载请保留链接
http://hongshengpeng.com/article/show/271.aspx
交易所集团:154950206 进群验证:88ios
版权声明:本文博客原创文章,博客,未经同意,不得转载。
Android Intent传递对象摘要的更多相关文章
- Android Intent传递对象小结
效果: 想看实例的,感兴趣的能够看之前的一篇文章 Android ViewPager Fragment实现选项卡 部分关键代码: public class SerializeActivity exte ...
- Android 全局获取 Context 与使用 Intent 传递对象
=====================全局获取 Context======================== Android 开发中很多地方需要用到 Context,比如弹出 Toast.启动活 ...
- Android开发——使用intent传递对象
intent传递对象有两种方法: 方式一:Serializable 方式 方式二:Parcelable方式 在这里不多介绍了,这一篇就是快速上手使用教程,至于详细原理介绍的,请看这一篇http://w ...
- android#使用Intent传递对象
参考自<第一行代码>——郭霖 Intent的用法相信你已经比较熟悉了,我们可以借助它来启动活动.发送广播.启动服务等.在进行上述操作的时候,我们还可以在Intent中添加一些附加数据,以达 ...
- Intent传递对象——Serializable和Parcelable差别
前两篇文章讨论了Serializable和Parcelable实现Intent之间传递对象和对象数组的方式.两种方法实现上相似,效果一致,怎么选择用哪种方法实现呢? Intent在不同的组件中传递对象 ...
- Intent传递对象的几种方式
原创文章.转载请注明 http://blog.csdn.net/leejizhou/article/details/51105060 李济洲的博客 Intent的使用方法相信你已经比較熟悉了,Inte ...
- 怎样使用Intent传递对象
怎样使用Intent传递对象 我们能够使用Intent来启动Activity.开启服务Service,发送广播Broadcast,然后使用Intent传递主要的数据类型,如:布尔值,整型,字符串等 I ...
- 关于intent传递对象后是传递的对象的地址还是对象的拷贝?
var intent = Intent(activity,SingleColorControlActivity::class.java); var bundle = Bundle()// bundle ...
- Android中Intent传递对象的两种方法(Serializable,Parcelable)
今天要给大家讲一下Android中 Intent中如何传递对象,就我目前所知道的有两种方法,一种是Bundle.putSerializable(Key,Object);另一种是 Bundle.putP ...
随机推荐
- [Angular] Using InjectionToken
Previously we have 'OpaqueToken', but it is DEPRECATED. The new one is called 'InjectionToken'. The ...
- C#验证手机号
using System.Text.RegularExpressions; private bool IsMobile(string phoneNo) { return Regex.IsMatch(p ...
- [Angular Directive] Build a Directive that Tracks User Events in a Service in Angular 2
A @Directive is used to add behavior to elements and components in your application. This makes @Dir ...
- 【机器学习实战】第7章 集成方法(随机森林和 AdaBoost)
第7章 集成方法 ensemble method 集成方法: ensemble method(元算法: meta algorithm) 概述 概念:是对其他算法进行组合的一种形式. 通俗来说: 当做重 ...
- Django日志器的使用
Logging Mudel A quick logging primer Django uses Python’s builtin logging module to perform system l ...
- pytharm运行django项目
pytharm运行django项目 安装Django 下载Django包,解压缩. CMD 进入解压路径下. 执行: python setup.py install 增加环境变量: C:\Pytho ...
- 【hdu 2594】Simpsons’ Hidden Talents
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s) ...
- [Flow] Declare types for application
In Flow, you can make global declarion about types. Run: flow init It will generate .flowconfig file ...
- [Angular] Difference between ViewChild and ContentChild
*The children element which are located inside of its template of a component are called *view child ...
- Wpf的布局舍入属性(可以解决软件字体模糊的问题)
原文:Wpf的布局舍入属性(可以解决软件字体模糊的问题) 版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/HK_JY/article/details/ ...