Intent传对象

来源:互联网 发布:js当前时间减去一个月 编辑:程序博客网 时间:2024/06/05 07:55
  1.  //Serializeable传递对象的方法    
  2.         public void SerializeMethod(){    
  3.             Person mPerson = new Person();    
  4.             mPerson.setName("frankie");    
  5.             mPerson.setAge(25);    
  6.             Intent mIntent = new Intent(this,ObjectTranDemo1.class);    
  7.             Bundle mBundle = new Bundle();    
  8.             mBundle.putSerializable(SER_KEY,mPerson);    
  9.             mIntent.putExtras(mBundle);    
  10.                 
  11.             startActivity(mIntent);    
  12.         }    
  13.         //Pacelable传递对象方法    
  14.         public void PacelableMethod(){    
  15.             Book mBook = new Book();    
  16.             mBook.setBookName("Android Tutor");    
  17.             mBook.setAuthor("Frankie");    
  18.             mBook.setPublishTime(2010);    
  19.             Intent mIntent = new Intent(this,ObjectTranDemo2.class);    
  20.             Bundle mBundle = new Bundle();    
  21.             mBundle.putParcelable(PAR_KEY, mBook);    
  22.             mIntent.putExtras(mBundle);    
  23.                 
  24.             startActivity(mIntent);    
  25.         } 
0 0
原创粉丝点击