开发学院手机开发Android 开发 Android中Intent传递对象的两种方法(Serializable... 阅读

Android中Intent传递对象的两种方法(Serializable,Parcelable)

 2010-10-19 20:18:07 来源:WEB开发网   
核心提示:import android.os.Bundle;import android.widget.TextView;public class ObjectTranDemo1 extends Activity {@Overridepublic void onCreate(Bundle savedInstanceState)

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());

上一页  2 3 4 5 6 7 8 9  下一页

Tags:Android Intent 传递

编辑录入:爽爽 [复制链接] [打 印]
[]
  • 好
  • 好的评价 如果觉得好,就请您
      0%(0)
  • 差
  • 差的评价 如果觉得差,就请您
      0%(0)
赞助商链接