2016-12-07 9 views

答えて

1

  1. 使用してアプリケーションをアンインストールし、コンテキストを使用して、アプリケーション内のどこからでもアクセスすることができるまでの値を保存しますこれは、SharedPreferenceを使用することができます。

  2. Extend Applicationクラスを拡張し、内部にグローバル変数を宣言し、getterメソッドとsetterメソッドを追加します。

そして、あなたの活動の

:それは私を助け、

class YourApplication extends Application { 
    private Integer globalValue; 

    public Integer getGlobalValue() { 
     return globalValue; 
    } 

    public void setGlobalValue(Integer value) { 
     globalValue = value; 
    } 
} 
+0

がそんなにあるVinodありがとう:

YourApplication yourApplication = (YourApplication) getApplicationContext(); yourApplication.setGlobalValue(10); yourApplication.getGlobalValue(); 

クラスを作成します。 –

+0

@SidharthMA:問題ありません。楽しい !! – Vinodh

1

これを実行する最も簡単な方法は、あなたが活動を開始するために使用している意図で第二の活動に変数を渡すために、次のようになります。

Intent intent = new Intent(getBaseContext(), SignoutActivity.class); 
intent.putExtra("variableKEY", variable); 
startActivity(intent) 

アクセス次の活動に熱心

こと
String s = getIntent().getStringExtra("variableKEY"); 

インテントのdocsにはさらに詳しい情報があります(「エクストラ」のセクションを参照)。グローバル変数については

From here

関連する問題