There are many ways to use global variables in Android, but there are few easy ways to do it, and a good way to do this is to find a video tutorial on the development of the Wheat Academy Android in the previous period:
public class MyApp extends application {
Private integer[] state;
Public integer[] GetState () {
return state;
}
public void SetState (integer[] state) {
This.state = State;
}
@Override
public void OnCreate () {
TODO auto-generated Method Stub
Super.oncreate ();
SetState (We);
}//Be sure to assign a value to the variable in the OnCreate method.
Public integer[] We=new integer[]{
R.drawable.b_0,r.drawable.b_1,r.drawable.b_2,
R.drawable.b_3,r.drawable.b_4,r.drawable.b_5
};
}
Use in the activity you need
MyApp appState = (MyApp) getapplicationcontext ();
integer[] we = appstate.getstate ();
To get, the last step don't forget to add Android:name= "in the application tag in manifest. MyApp "(Here is not new <application></application>)
More Android Development tutorials at: Http://www.maiziedu.com/course/android/
Getting Started with Android: Android uses global variables