Android Intent :-Use Intent to pass class objects from Activities [duplicate]

假如想象 提交于 2019-12-23 07:46:26

问题


Possible Duplicate:
How to send an object from one Android Activity to another using Intents?

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?


回答1:


You can use Serializable or Parcelable

If you use Serializable you only have to implement it by writing implements Serializable

If you use Parcelable you have to fill in the used methodes. See: http://developer.android.com/reference/android/os/Parcelable.html

Read about the differences here: http://www.mooproductions.org/node/6

Conclusion: Parcelable is really alot faster but takes more time to implement.




回答2:


In order to pass your custom objects through Intent, you need to make sure that your class implements Parcelable.

For more info, read this tutorial.



来源:https://stackoverflow.com/questions/12820758/android-intent-use-intent-to-pass-class-objects-from-activities

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!