This is Application class. It is Saving int value.
public class TestApplication extends Application { public class TestApp extends Application { private int _number = 0; @Override public void onCreate() { Log.d("test", "onCreate"); } @Override public void onTerminate() { Log.d("test", "onTerminate"); } public void setNumber(int number){ Log.d("test", "setNumber"); _number = number; } public int getNumber(){ Log.d("test", "getNumber"); return _number; } }
This is Setter Activity for application class.
_testApp = (TestApp) this.getApplication(); _testApp.setNumber(8); Log.d("test", "Number = "+ _testApp.getNumber());
And wake up getter Activity.
Intent intent = new Intent(); intent.setClass(this, TesterActivity.class); startActivity(intent);
This is getter Activity.
_testApp = (TestApp) this.getApplication(); Log.d("test", "Tester Number = "+ _testApp.getNumber());
This application Log:
onCreate setNumber getNumber Number = 8 getNumber Tester Number = 8I must change Android Manifest.xml
source code is here.
0 件のコメント:
コメントを投稿