編輯:Android開發教程
Android中Intent中如何傳遞對象,就我目前所知道的有兩種方法,一種是Bundle.putSerializable(Key,Object);另一種是Bundle.putParcelable(Key, Object);當然這些Object是有一定的條件的,前者是實現了Serializable接口,而後者是實現了Parcelable接口,為了讓大家更容易理解我還是照常寫了一個簡單的Demo,大家就一步一步跟我來吧!
第一步:新建一個Android工程命名為ObjectTranDemo(類比較多哦!)目錄結構如下圖:

第二步:修改main.xml布局文件(這裡我增加了兩個按鈕)代碼如下
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Welcome to Mr wei's blog."
/>
<Button
android:id="@+id/button1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Serializable"
/>
<Button
android:id="@+id/button2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Parcelable"
/>
</LinearLayout>
第三步:新建兩個類一個是Person.java實現Serializable接口,另一個Book.java實現Parcelable接口,代碼分別如下:
Person.java:
package com.tutor.objecttran;
import java.io.Serializable;
public class Person implements Serializable {
private static final long serialVersionUID = -7060210544600464481L;
private String name;
private int age;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
}
Android簡明開發教程十二:引路蜂二維圖形庫簡介及顏色示例
AndroidGraphics2DTutorial定義了應用的主Activity,下面就可以開始寫每個具體的二維繪圖示例。不同的例子將盡量采用 不同的UI控件:Menu,
開發可統計單詞個數的Android驅動程序(中)
五、指定與驅動相關的信息雖然指定這些信息不是必須的,但一個完整的Linux驅動程序都會指定這些與驅動相關的信息。一般需要為Linux驅動程序指定如下信息。1. 模塊作者:
基於Android 4.4系統的nubia UI 2.0
5月15日nubia UI 2.0開啟公測(基於Android 4.4),首批機型:Z5、Z5 mini、Z5S mini。全新的nubia UI 2.0,扁平、簡約的U
Android數據存儲之File文件儲存數據
Android數據儲存之File文件儲存數據 一.存儲在內部還是外部? AndroidManifest.xml中manifest標簽下有一個屬性andro