0

I have this class that I use to configure the Usb connection with a external device. It works ok on my activity android, but I would like to pass it to another activity, but I'm not able to do that. I'm trying to serialize the class to pass to another activity but when I call startactivity the other activity comes a exception.

This is when I call the activity:

Intent lights = new Intent(this, Screen2Activity.class);
lights.putExtra("usb", usb);
startActivity(lights);

The exception is: java.lang.RuntimeException: Parcelable encountered IOException writing serializable object (name = com.example.vcontrol.Usb)

This is my class:

//-----------------------------------------------------------
//
// Class that configures and communicates with the Usb Port
//
//-----------------------------------------------------------

public class Usb implements Serializable {

//USB Parameters and Controls
private UsbManager usbManager = null;
private UsbDeviceConnection conn = null;
private UsbDevice device = null;
private UsbInterface usbIf = null;
private UsbEndpoint epIN = null;
private UsbEndpoint epOUT = null;
...

Somebody can help me?

Ebbe M. Pedersen
  • 7,250
  • 3
  • 27
  • 47
andrewmm
  • 1
  • 2

2 Answers2

0

yes, only if they are Serializable, if you don't control the class then you're out of luck.

T McKeown
  • 12,971
  • 1
  • 25
  • 32
0

Q: Very important question ... ?? What exactly is the exception ??

My guess is java.IO.NotSerializableException.

If so, you basically have two choices:

1) Modify your class so that it implements Serializable

... or ...

2) Extend your class, and have the new subclass implement Serializable.

Here are more details:

http://docs.oracle.com/javase/7/docs/api/java/io/Serializable.html

http://www.vogella.com/articles/JavaSerialization/article.html

============ ADDENDUM ============

Thank you for your update! I believe this is the solution

Passing data through intent using Serializable

// Example "serialize"
Bundle bundle = new Bundle();  
bundle.putSerializable("value", all_thumbs);
intent.putExtras(bundle);

// Example "deserialize"
Intent intent=this.getIntent();
Bundle bundle=intent.getExtras();

List<Thumbnail> thumbs=
               (List<Thumbnail>)bundle.getSerializable("value");
Community
  • 1
  • 1
FoggyDay
  • 11,962
  • 4
  • 34
  • 48
  • Ok! Thanks. One doubt... To serialize a class Do I need only put the "implements Serializable" in my class? I've just made this! – andrewmm Dec 28 '13 at 05:50