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

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

 2010-10-19 20:18:07 来源:WEB开发网   
核心提示:setContentView(mTextView);}}package com.tutor.objecttran;import android.app.Activity;import android.os.Bundle;import android.widget.TextView;public class Object

setContentView(mTextView);

}

}

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

setContentView(mTextView);

}

}

第五步:比较重要的一步啦,修改AndroidManifest.xml文件(将两个新增的Activity,ObjectTranDemo1,ObjectTranDemo2)申明一下代码如下(第14,15行):

view plaincopy to clipboardprint?

< ?xml version="1.0" encoding="utf-8"?>

< manifest xmlns:android="http://schemas.android.com/apk/res/android"

package="com.tutor.objecttran"

android:versionCode="1"

android:versionName="1.0">

< application android:icon="@drawable/icon" android:label="@string/app_name">

< activity android:name=".ObjectTranDemo"

android:label="@string/app_name">

< intent-filter>

< action android:name="android.intent.action.MAIN" />

< category android:name="android.intent.category.LAUNCHER" />

< /intent-filter>

< /activity>

< activity android:name=".ObjectTranDemo1">< /activity>

< activity android:name=".ObjectTranDemo2">< /activity>

< /application>

< uses-sdk android:minSdkVersion="7" />

< /manifest>

< ?xml version="1.0" encoding="utf-8"?>

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

Tags:Android Intent 传递

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接