Android中Context简介
2012-07-02 21:25
260 查看
The way to do this is to create your own subclass of android.app.Application, and then specify that class in the application tag in your manifest. Now Android will automatically create an instance of that class and make it available for your entire application. You can access it from any context using the Context.getApplicationContext() method (Activity also provides a method getApplication() which has the exact same effect):
classMyAppextendsApplication{ privateString myState; publicString getState(){ return myState; } publicvoid setState(String s){ myState = s; } } classBlahextendsActivity{ @Override publicvoid onCreate(Bundle b){ ... MyApp appState =((MyApp)getApplicationContext()); String state = appState.getState(); ... } }
相关文章推荐
- Android中Context简介
- Android Context简介
- Android Context简介
- Android中Context简介
- Android Context简介
- Android Context简介
- Android中Context简介
- Android中Context简介
- Android Context简介
- Android Context简介
- Android中Context简介(通俗易懂)
- Android Context简介
- Android Context简介
- Android中Context简介
- Android中Context简介
- Android中Context简介
- Android Context简介
- Context——Android中Context简介
- Android中Context简介
- Android Context简介