android intent 传递list或者对象
来源:互联网 发布:手机麻将游戏源码 编辑:程序博客网 时间:2024/03/29 05:52
原文网址:2011.07.19——— android intent 传递list或者对象
方法一:
如果单纯的传递List<String> 或者List<Integer>的话 就可以直接使用
intent.putStringArrayListExtra(name, value)intent.putIntegerArrayListExtra(name, value)
方法二:
如果传递的是List<Object>,可以把list强转成Serializable类型,然后通过
putExtras(key, (Serializable)list)
方法传递过去,接受的时候用
List<Object> list = (List<Object>) getIntent().getSerializableExtra("list");
就可以接受到List<Object>数据了,但是 切记 你的YourObject类必须要实现Serializable接口
方法三:
一种是
Bundle.putSerializable(Key,Object);
另一种是
Bundle.putParcelable(Key, Object);
当然这些Object是有一定的条件的,前者是实现了Serializable接口,而后者是实现了Parcelable接口
方法四:
用intent传来传去 觉得不方便 我们可以写一个在application里面的全局数据
1、创建一个属于你自己的android.app.Application的子类
2、在manifest中申明一下这个类,
3、这时android就为此建立一个全局可用的实例,你可以在其他任何地方使用Context.getApplicationContext()方法获取这个实例,进而获取其中的状态(变量)。
继承Application
class MyApp extends Application { private String myState; public String getState(){ return myState; } public void setState(String s){ myState = s; }}
关于AndroidManifest.xml中的配置,原来直接给application加个name就可以了,如下面所示:
<application android:name=".MyApp" android:icon="@drawable/icon"android:label="@string/app_name">
使用
class Blah extends Activity { @Override public void onCreate(Bundle b){ ... MyApp appState = ((MyApp)getApplicationContext()); String state = appState.getState(); ... }}
- android intent 传递list或者对象
- android intent 传递list或者对象
- android intent 传递list或者对象
- android intent 传递list或者对象
- android intent 传递list或者对象
- android intent 传递list或者对象
- android intent 传递list或者对象
- android intent 传递list或者对象
- android intent 传递list或者对象
- android intent 传递list或者对象
- Android使用Intent传递List或者对象
- android intent 传递list或者对象
- android intent 传递list或者对象
- android intent 传递list或者对象
- android intent 传递list或者对象
- android intent 传递list或者对象
- Android Intent 传递List或者对象
- android intent 传递list或者对象
- 「命名空间内部使用的名字的查找」与「类成员定义中使用的名字的查找」的区别
- IOS开发:apple.com上无法下载xcode
- 在地图中使用摄像机
- android基础篇------------java基础(3) (数组和String的应用)
- 只进结果集不支持请求的操作的“解决方法”
- android intent 传递list或者对象
- Lesson 6 Beautiful campusc
- VC下如果操作Excel
- ORA-32004: obsolete and/or deprecated parameter(s) specified
- 树形dp之节点对 poj1741
- hdu4190
- Win32下的打印作业输出
- iOS 取得CGimage字节数据的方法
- uiimage 转换为像素数据 以及从像素数据生成为uiimage