Android中Intent传递对象的两种方法(Serializable,Parcelable)
2010-10-19 20:18:07 来源:WEB开发网import android.os.Bundle;
import android.widget.TextView;
public class ObjectTranDemo1 extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
TextView mTextView = new TextView(this);
Person mPerson = (Person)getIntent().getSerializableExtra(ObjectTranDemo.SER_KEY);
mTextView.setText("You name is: " + mPerson.getName() + " "+
"You age is: " + mPerson.getAge());
setContentView(mTextView);
}
}
package com.tutor.objecttran;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
public class ObjectTranDemo1 extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
TextView mTextView = new TextView(this);
Person mPerson = (Person)getIntent().getSerializableExtra(ObjectTranDemo.SER_KEY);
mTextView.setText("You name is: " + mPerson.getName() + " "+
"You age is: " + mPerson.getAge());
setContentView(mTextView);
}
}
ObjectTranDemo2.java:
package com.tutor.objecttran;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
public class ObjectTranDemo2 extends Activity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
TextView mTextView = new TextView(this);
Book mBook = (Book)getIntent().getParcelableExtra(ObjectTranDemo.PAR_KEY);
mTextView.setText("Book name is: " + mBook.getBookName()+" "+
"Author is: " + mBook.getAuthor() + " " +
"PublishTime is: " + mBook.getPublishTime());
更多精彩
赞助商链接