Getting Started with Android: Android uses global variables

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.