Android全局变量
public class MyApp extends Application { private String myState; public String getState(){ return myState; } public void setState(String s){ myState = s; } } public 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"> <activity android:name=".ClickableListItemActivity" android:label="@string/app_name"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application>
说明:
需添加的内容:android:name=".your_App_Name"
位置:当前activity所在的位置
相关推荐
luoj 2011-09-12
androidstudyroom 2011-08-19
TTHHVV 2011-12-05
peixiaopao 2012-05-06
ruanjianxiong 2012-05-23
fanjunjian 2015-03-03
Nostalgiachild 2014-11-02
oLimxing 2014-07-21
Jemy杰 2013-04-26
redbricks 2013-01-18
mlsnatalie 2012-10-21
家猫OR野猫 2012-05-11
crazymaple 2012-03-23
xiaozhifree 2012-02-27
西木 2012-01-03
xfcyhades 2011-10-07
刘炳昭 2011-08-15
dianlunhui 2011-06-13
wangkuifeng0 2011-05-26