Android开发必备:揭秘Intent可传递的10种数据类型
在Android开发中,Intent可以传递多种数据类型,包括: 1. String:可以传递字符串类型的数据。 ```java Intent intent = new Intent(); intent.putExtra("key", "value"); ``` 2. Integer:可以传递整型类型的数据。 ```java Intent intent = new Intent(); intent.putExtra("key", 123); ``` 3. Double:可以传递浮点型类型的数据。 ```java Intent intent = new Intent(); intent.putExtra("key", 123.45); ``` 4. Boolean:可以传递布尔型类型的数据。 ```java Intent intent = new Intent(); intent.putExtra("key", true); ``` 5. Parcelable:可以传递可序列化对象的数据。 ```java Intent intent = new Intent(); MyParcelableObject obj = new MyParcelableObject(); intent.putExtra("key", obj); ``` 6. Serializable:可以传递可序列化对象的数据,但是这种方式并不推荐使用,因为 Serializable 对象可能会暴露敏感信息。 7. Bundle:可以传递键值对的数据。 ```java Intent intent = new Intent(); Bundle bundle = new Bundle(); bundle.putString("key", "value"); intent.putExtras(bundle); ``` 8. File:可以传递文件数据。 ```java Intent intent = new Intent(); File file = new File("/path/to/file"); intent.putExtra("key", file); ``` 9. Bitmap:可以传递位图数据。 ```java Intent intent = new Intent(); Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.my_image); intent.putExtra("key", bitmap); ``` 10. ArrayList:可以传递 ArrayList 数据。 ```java Intent intent = new Intent(); ArrayList<String> list = new ArrayList<>(); list.add("item1"); list.add("item2"); intent.putExtra("key", list); ``` ######[AI写代码神器 | 373点数解答 | 2023-11-07 22:47:31]
- RealtimeMonitoringFragment 代码片段:Android 实时监控功能核心代码剖析(字节豆包 | 30点数解答 | 2024-10-12 10:31:18)294
- 揭秘:Android实时监控片段(RealTimeMonitoringFragment)代码实现(GPT | 531点数解答 | 2024-10-12 10:32:25)269
- AIDE编写Xposed软件:参考代码教你拦截Smail类方法名(阿里通义 | 649点数解答 | 2024-10-12 00:15:48)305
- bookmanage 数据库表创建、测试数据添加及多需求 SQL 操作全解析(GPT | 909点数解答 | 2024-06-22 22:25:19)410
- WinForm实现图书管理系统:数据库操作、界面设计与功能全解析(GPT | 1163点数解答 | 2024-06-22 22:26:42)367
- Android Studio开发:打造多页面交互美团选购App,附代码示例与注意要点! (字节豆包 | 293点数解答 | 2024-11-29 01:16:56)302
- Android Studio 开发:功能完备且流畅运行的美团选购 APP 大揭秘!(GPT | 291点数解答 | 2024-11-29 01:17:30)228
- 智能电话窗口按钮1弹起:获取坐标与手机IMEI码待处理(GPT | 208点数解答 | 2024-09-12 16:36:31)353
- 易语言多线程启动:如何传递并处理文本数组及注意要点(字节豆包 | 610点数解答 | 2025-08-04 18:05:23)180
- Java、C++、Python 三语言:输入三整数输出最小值程序实现(字节豆包 | 441点数解答 | 2024-11-01 16:41:00)190
- Python:用if语句找出输入的三个整数中的最小值(GPT | 176点数解答 | 2024-11-01 16:41:27)247
- Android开发必知:android:layout_gravity与android:gravity的区别解析(阿里通义 | 299点数解答 | 2023-11-07 22:38:25)359