android intent 传递list或者对象
方法一:
如果单纯的传递List<String> 或者List<Integer>的话 就可以直接使用
Java代码
intent.putStringArrayListExtra(name, value)
intent.putIntegerArrayListExtra(name, value)
方法二:
如果传递的是List<Object>,可以把list强转成Serializable类型,然后通过
Java代码 putExtras(key, (Serializable)list)
方法传递过去,接受的时候用
Java代码 (List<YourObject>) getIntent().getSerializable(key)
就可以接受到List<YourObject>数据了
但是 切记 你的YourObject类必须要实现Serializable接口
方法三:
一种是
Java代码 Bundle.putSerializable(Key,Object);
另一种是
Java代码 Bundle.putParcelable(Key, Object);
当然这些Object是有一定的条件的,前者是实现了Serializable接口,而后者是实现了Parcelable接口
一、传递List<String>和List<Integer>
以下以传递List<String>为例,发送List<String>语法为:
intent.putStringArrayListExtra(key, list);
接收List<String>的语法为:
list = (ArrayList<String>)getIntent().getStringArrayListExtra(key);
以下是一个运用实例:
ArrayList<String> stringList = new ArrayList<String>();
stringList.add("string1");
stringList.add("string2");
stringList.add("string3");
Intent intent = new Intent();
intent.setClass(ListDemoActivity.this, StringListActivity.class);
intent.putStringArrayListExtra("ListString", stringList);
startActivity(intent);
接收
ArrayList<String> stringList = (ArrayList<String>) getIntent().getStringArrayListExtra("ListString");
List<Integer>类似以上的操作调用下面的方法也可以实现发送和接收:
intent.putIntegerArrayListExtra(key, list);
list =(ArrayList<Integer>) getIntent().getIntegerArrayListExtra(key);
Intent 传递String 字符串
intent.putExtra("key", "hello, world!");
接收端写法:
Intent intent = getIntent(); intent.getStingExtra("key"),如果key对应的字符串没有找到则得到null;
相关推荐
Activity之间是没有办法直接传递数据的。...但是Intent的传送效率也不是很高,特别是当传递一些如Bitmap的大数据,曾经在有一次遇到过,用Intent传递超过500K的Bitmap,就会造成Framework层的Java Binder挂掉,
第7章 Android中的核心Intent 7.1 Intent的作用 7.1.1 多Activity的Android应用 7.1.2 Activity之间的消息传递 7.2 Intent的分类 7.2.1 Action Intent 7.2.2 Broadcast Intent 7.3 解析Intent的实现 7.3.1 Intent ...
在应用中,可能会在当跳转到另外一个Activity的时候需要传递数据... //new一个Bundle对象,并将要传递的数据导入,Bunde相当于Map结构 Bundle bundle = new Bundle(); bundle.putString(“name”,”Livingstone”); b
第4部分(9-13章):第9章讲解了Android的数据存储结构,以及不同数据存储模式的使用要点;第10章分析了Android的各种网络连接方式,涵盖NFC和基于Wifi的P2P连接等内容;第11章讲解了Android的定位服务、地址解析...
----------------------------------- Android 编程基础 1 封面----------------------------------- Android 编程基础 ...• SQLite SQLite SQLite SQLite 用作结构化的数据存储 • 多媒体支持 包括常见的音频、视频和...
Intent 数据结构两个最重要的部分是动作和动作对应的数据。Intent类绑定一次操作,它负责 携带这次操作所需要的数据以及操作的类型等。 3、Layout 用于用户界面设计。包含AbsoluteLayout, FrameLayout,GridView, ...
2.1.1 各种库和android运行环境 2.1.2 应用程序框架 2.1.3 操作系统层 2.1.4 应用程序 2.2 android应用程序组成 2.2.1 activity 2.2.2 intent和intent filter 2.2.3 service介绍 2.2.4 broadcastintentreceiver ...
我们知道,Intent主要用来激活安卓几大组件,那么它具体是怎样来激活的?激活时是否可以携带java对象?为何要将对象序列化后...Intent数据结构: action:所要执行的动作;(例如:ACTION_CALL创建打电话Activity;
2.5 剖析Android应用程序的结构 2.6 分析Notepad应用程序 2.6.1 加载和运行Notepad应用程序 2.6.2 分解应用程序 2.7 了解应用程序生命周期 2.8 调试应用程序 2.8.1 启动模拟器 2.8.2 ...
1.5 Android应用结构分析 24 1.5.1 创建一个Android应用 24 1.5.2 自动生成的R.java 26 1.5.3 res目录说明 27 1.5.4 Android应用的清单文件: AndroidManifest.xml 28 1.5.5 应用程序权限说明 29 ...
16、Intent传递数据时,下列的数据类型那些可以被传递(ABCD) A、Serializable B、charsequence C、Parcelable(邮包类型) D、Bundle 17、Android中使用Menu时可能需要重写的方法(AC) A、onCreateOptionsMenu() B、...
目录结构: 第2章、Android应用程序界面设计,即View 2.2、布局管理(Layout):LinearLayout、TableLayout、FrameLayout、RelativeLayout; 2.3、基本界面组件:TextView、EditText; Button、ImageButton; 9Patch; ...
疯狂Android讲义目录结构: 第2章、Android应用程序界面设计,即View 2.2、布局管理(Layout):LinearLayout、TableLayout、FrameLayout、RelativeLayout; 2.3、基本界面组件:TextView、EditText; Button、...
概述1.1安卓系统架构1.2Android四大组件1.3项目结构1.4app目录结构1.5 项目运行原理1.6 res目录详解1.7日志工具的使用第二章 活动2.1 创建基本活动2.2 使用Intent在活动之间跳转2.2.1使用显示和隐式Intent2.2.2隐式...
2.3.6 秘诀11:在activity 间传递基本数据类型 37 第3 章 线程、服务、receiver 以及alert 对话框 40 3.1 线程 40 3.1.1 秘诀12:启动一个辅助线程 40 3.1.2 秘诀13:创建实现runnable接口的activity 44 3.1.3 ...
2.5 剖析Android应用程序的结构 2.6 分析Notepad应用程序 2.6.1 加载和运行Notepad应用程序 2.6.2 分解应用程序 2.7 了解应用程序生命周期 2.8 调试应用程序 2.8.1 启动模拟器 2.8.2 ...