把对象作为意向的下一个活动 [英] Put Object as intent for next activity

查看:157
本文介绍了把对象作为意向的下一个活动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可能把Object类型的对象转换意图作为一个额外的?我有一个Object类型的变量,也不会知道,直到它被分配一个值作为对象数据类型是什么。也许是与序列化,也可以捆绑我不知道?然后在接下来的活动我怎么那么得到这个值,以便将其存储在一个的ArrayList<对象>

Is it possible to to put an object of type Object into an intent as a Extra? I have a variable of type object and won't know until it is assigned a value as to what the object datatype is. Maybe something to do with serialization or as a bundle i'm not sure? And then in the next activity how do I then get this value in order to store it in an ArrayList<Object> ?

推荐答案

捆绑 通过的方式意图#putExtra 没有任何功能添加一个对象。您只能通过在 Parcelable 或<一href="http://developer.android.com/reference/java/io/Serializable.html"><$c$c>Serializable目的。你想通过意图通过任何物体必须实现这些接口中的一个。它的建议落实 Parcelable 有一个简短的指南在这里:通行证通过使用parcelables的值参数。

Bundle by way of Intent#putExtra does not have any function to add an Object. You can only pass in a Parcelable or a Serializable object. Any object you want to pass via an Intent must implement one of those interfaces. It's recommended to implement Parcelable there is a brief guide here: Pass by value Parameters using Parcelables.

另外这个问题有更多的有用的答案:<一href="http://stackoverflow.com/questions/2139134/how-to-send-an-object-from-one-android-activity-to-another-with-intent-putextra">How从一个Android的活动将对象到另一个使用意图?

Also this question has more helpful answers: How to send an object from one Android Activity to another using Intents?

这篇关于把对象作为意向的下一个活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆