Android的意图: - 使用意图传递从活动类对象 [英] Android Intent :-Use Intent to pass class objects from Activities
问题描述
可能重复:
<一href="http://stackoverflow.com/questions/2139134/how-to-send-an-object-from-one-android-activity-to-another-using-intents">How从一个Android的活动将对象到另一个使用意图?
我想从一个Activity类对象传递给其他当一个活动呼吁其他。我试图使用 Intent.putExtra(名称,值)
来做出,但随后我不有 Intent.getExtra(名称)
方法。有很多方法,如 getStringExtra(名称)
, getDataExtra(名称)
等等,但我放 putExtra
的值是有很多不同的值作为字符串,数据和int的类对象。我怎样才能让通过这门课吗?
I want to pass a class object from an Activity to other when one Activity calls to the other. I am trying to use Intent.putExtra(name, value)
to make that but then I don´t have Intent.getExtra(name)
method. There are a lot of methods like getStringExtra(name)
, getDataExtra(name)
and so on but what I put in the value of putExtra
is a class object that have a lot of different values as String, Data and int. How can I make to pass that class?
推荐答案
您可以使用序列化
或 Parcelable
如果您使用序列化
您只有通过写实现Serializable
If you use Serializable
you only have to implement it by writing implements Serializable
如果您使用 Parcelable
您必须填写使用methodes。请参阅: http://developer.android.com/reference/android/os/Parcelable html的
If you use Parcelable
you have to fill in the used methodes. See: http://developer.android.com/reference/android/os/Parcelable.html
了解更多关于这里的区别: http://www.mooproductions.org/node/6
Read about the differences here: http://www.mooproductions.org/node/6
结论: Parcelable
真是快得多,但需要更多的时间来实施
Conclusion: Parcelable
is really alot faster but takes more time to implement.
这篇关于Android的意图: - 使用意图传递从活动类对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!