Android 使用全局變量

1.首先定義一個類繼承Application類:

package cn.com.smartcost.cld.entity;

import android.app.Application;

/**
 * APP的全局變量
 * @author wangfeng
 * @date 2013-12-18 15:23:34
 */
public class AppData extends Application {
	private User user;

	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}
	

	
	
	
}

2.在AndroidManifest.xml中指定:


3.保存:

appData = (AppData)getApplication();

appData.setUser(user);

4.獲取:

appData = (AppData)getApplication();

appData.getUser();

發佈留言