全域變數

1. 設定AndroidManifest

<application
    android:name=".GlobalVariable"
    ....
2. 建立共用變數類別

public class GlobalVariable extends Application {
    private String msg;

    public String getMsg(){
        return  msg;
    }

    public void setMsg(String Msg){
        this.msg=Msg;
    }

}
3. 儲存、取得共用變數

    //放入
    GlobalVariable globalVariable = (GlobalVariable)getApplicationContext();
    globalVariable.setMsg("這是內容");

    //取出
    GlobalVariable globalVariable = (GlobalVariable)getApplicationContext();
    String text=globalVariable.getMsg()