- class MyApp extends Application {
- private String myState;
- public String getState() {
- return myState;
- }
- public void setState(String s) {
- myState = s;
- }
- }
在AndroidManifest.xml的application加个name属性就可以了,如下面所示:
android:name=".MyApp" android:icon="@drawable/icon"
android:label="@string/app_name">
- class Blah extends Activity {
- Override
- public void onCreate(Bundle b){
- ...
- MyApp appState = ((MyApp)getApplicationContext());
- String state = appState.getState();
- ...
- }
- }