酷代码 AI
菜单
全部AI  /  热门  /  AI问答
服务商

在android开发中,intent可传递的数据类型

在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); ``` [2023-11-07 22:47:31 | AI问答 | 373点数解答]

相关提问