Problems with Serializable

Put problem concerning Views, Layouts and other XML-Resources (like AndroidManifest) here.

Problems with Serializable

Postby diegomobilefleet » Wed Oct 14, 2009 3:22 pm

I have a problem with a program that I `m design:

public void LoadVehicules()
{
Intent intent=new Intent(this,pspsl.g.listviewrealtimeinfo.class);
intent.putExtra("doGetInfoRealTimeResult", doGetInfoRealTimeResult.toString());
intent.putExtra("doGetInfoRealTimeResult", true);
startActivity(intent);
}

doGetinfoRealTimeResult type is Array of Objects and I want to pass this array list to another window of the program to put the information that it contain in the screen.

My problem is, How Can I serializable an array list of objects??

Thanks.
diegomobilefleet
Freshman
Freshman
 
Posts: 4
Joined: Wed Oct 07, 2009 3:46 pm

Top

Postby padde » Wed Oct 14, 2009 5:25 pm

Each object in the object array needs to implement the serializable interface.
The example below works well..


Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. class A implements Serializable {
  3.  
  4.         private static final long serialVersionUID = 1L;
  5.  
  6.        
  7.  
  8.         private int muh;
  9.  
  10.         private String wuff;
  11.  
  12.         private HashMap<String, String> miau;
  13.  
  14.        
  15.  
  16.         public A() { this.muh = 1; this.wuff = "2"; this.miau = new HashMap<String,String>(); }
  17.  
  18. }
  19.  
  20.  
  21.  
  22. class B implements Serializable {
  23.  
  24.         private static final long serialVersionUID = 2L;
  25.  
  26.        
  27.  
  28.         private A myA;
  29.  
  30.        
  31.  
  32.         public B() { this.myA = new A(); }
  33.  
  34. }
  35.  
  36.  
  37.  
  38. public class Test extends Activity {
  39.  
  40.     public void onCreate(Bundle savedInstanceState) {
  41.  
  42.         super.onCreate(savedInstanceState);
  43.  
  44.         setContentView(R.layout.main);
  45.  
  46.        
  47.  
  48.         Intent i = new Intent(this, Test.class);
  49.  
  50.         i.putExtra("test", new A());
  51.  
  52.         i.putExtra("test", new B());
  53.  
  54.        
  55.  
  56.         ArrayList<B> blist = new ArrayList<B>();
  57.  
  58.         blist.add(new B());
  59.  
  60.         blist.add(new B());
  61.  
  62.         blist.add(new B());
  63.  
  64.        
  65.  
  66.         ArrayList<A> alist = new ArrayList<A>();
  67.  
  68.         alist.add(new A());
  69.  
  70.         alist.add(new A());
  71.  
  72.         alist.add(new A());
  73.  
  74.        
  75.  
  76.         i.putExtra("test", alist);
  77.  
  78.         i.putExtra("test", blist);
  79.  
  80.  
  81.  
  82.         startActivity(i);
  83.  
  84.     }
  85.  
  86. }
  87.  
  88.  
Parsed in 0.036 seconds, using GeSHi 1.0.8.4
padde
Master Developer
Master Developer
 
Posts: 443
Joined: Wed Apr 08, 2009 4:52 pm

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: No registered users and 5 guests