android中全局变量的使用方法:
class MyApp extends Application { private String myState; public String getState(){ return myState; } public void setState(String s){ myState = s; } }
class Blah extends Activity { @Override public void onCreate(Bundle b){ … MyApp appState = ((MyApp)getApplicationContext()); String state = appState.getState(); … } }
在manifest中定义:
<application android:name=”.MyApp” android:icon=”@drawable/icon” android:label=”@string/app_name”>