在Intent间传递Object对象的方法

1. 将类实现Serializable接口,本如我的类ServerClass.java

package com.zhai.dao;

import java.io.Serializable;

public class ServerClass implements Serializable {

    private static final long serialVersionUID = -6708650608486703053L;
    private String id;
    private String name;
    private String IP;
    private String username;
    private String password;
    private String domain;
    private String des; // 描述

    /**
     * @return the id
     */
    public String getId() {
        return id;
    }

    /**
     * @param id
     *            the id to set
     */
    public void setId(String id) {
        this.id = id;
    }

    private int[] resolution; // 包括宽和高 第一个为宽度 , 第二个为高度F
    private int color;
    private String key_layout;
    private boolean bConsole;

    public ServerClass(String name, String iP, String username,
            String password, String domain, String des, int[] resolution,
            int color, String key_layout, boolean bConsole) {
        super();
        this.name = name;
        IP = iP;
        this.username = username;
        this.password = password;
        this.domain = domain;
        this.des = des;
        this.resolution = resolution;
        this.color = color;
        this.key_layout = key_layout;
        this.bConsole = bConsole;
    }

    /**
     * @return the name
     */
    public String getName() {
        return name;
    }

    /**
     * @param name
     *            the name to set
     */
    public void setName(String name) {
        this.name = name;
    }

    /**
     * @return the iP
     */
    public String getIP() {
        return IP;
    }

    /**
     * @param iP
     *            the iP to set
     */
    public void setIP(String iP) {
        IP = iP;
    }

    /**
     * @return the username
     */
    public String getUsername() {
        return username;
    }

    /**
     * @param username
     *            the username to set
     */
    public void setUsername(String username) {
        this.username = username;
    }

    /**
     * @return the password
     */
    public String getPassword() {
        return password;
    }

    /**
     * @param password
     *            the password to set
     */
    public void setPassword(String password) {
        this.password = password;
    }

    /**
     * @return the domain
     */
    public String getDomain() {
        return domain;
    }

    /**
     * @param domain
     *            the domain to set
     */
    public void setDomain(String domain) {
        this.domain = domain;
    }

    /**
     * @return the des
     */
    public String getDes() {
        return des;
    }

    /**
     * @param des
     *            the des to set
     */
    public void setDes(String des) {
        this.des = des;
    }

    /**
     * @return the resolution
     */
    public int[] getResolution() {
        return resolution;
    }

    /**
     * @param resolution
     *            the resolution to set
     */
    public void setResolution(int[] resolution) {
        this.resolution = resolution;
    }

    /**
     * @return the color
     */
    public int getColor() {
        return color;
    }

    /**
     * @param color
     *            the color to set
     */
    public void setColor(int color) {
        this.color = color;
    }

    /**
     * @return the key_layout
     */
    public String getKey_layout() {
        return key_layout;
    }

    /**
     * @param key_layout
     *            the key_layout to set
     */
    public void setKey_layout(String key_layout) {
        this.key_layout = key_layout;
    }

    /**
     * @return the bConsole
     */
    public boolean isbConsole() {
        return bConsole;
    }

    /**
     * @param bConsole
     *            the bConsole to set
     */
    public void setbConsole(boolean bConsole) {
        this.bConsole = bConsole;
    }

}

2.发送到另一个Activity

ServerClass Item = (ServerClass) parent.getAdapter().getItem(
                        position);

                Intent intent = new Intent(Activity_ServerList.this,
                        Activity_Desktop.class);
                intent.putExtra("SERVER_INFO", Item);

                startActivity(intent);

3.在另一个Activity中接收

Intent intent = getIntent();
        ServerClass serverInfo = (ServerClass) intent
                .getSerializableExtra("SERVER_INFO");
        // 得到一些参数
        Toast.makeText(Activity_Desktop.this, serverInfo.getName(),
                Toast.LENGTH_LONG).show();