Android Intent: -Use intent to pass class objects from Activity

Possible duplicate:
How to send an object from one Android activity to another using intentions?

I want to transfer a class object from Activity to another when one action calls another. I am trying to use Intent.putExtra(name, value) to do this, but then I have no Intent.getExtra(name) method. There are many methods, such as getStringExtra(name) , getDataExtra(name) , etc., but what I put in putExtra is an object of the class that has many different values ​​like String, Data and int. How can I execute this class?

+6
source share
2 answers

You can use Serializable or Parcelable

If you are using Serializable , you need to implement it by writing implements Serializable

If you are using Parcelable , you must fill in the methods used. See: http://developer.android.com/reference/android/os/Parcelable.html

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

Conclusion: Parcelable really much faster, but it takes more time to implement.

+2
source

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

Read this tutorial for more information.

0
source

Source: https://habr.com/ru/post/927356/


All Articles