In practical applications we often need to interact with and save the data, but the default method in intent has a type limit on the transmission of data, when we need to transfer or save a complex generic data, the use of application is a good solution.
As the name implies, application corresponds to the entire application, just as the activity corresponds to the current active window, and when we need to use it, be sure to declare it in Androidmanifest.xml.
<application android:name = " meterapplication Android: Allowbackup = true " Android:icon =" @drawable/ic_launcher " Android:label = @string/app_name " Android:theme =" @style/apptheme > </application>
Then we come to the entity class, first, when other classes need to be accessed or called, first call this class of getinstance () to get Meterapplication objects, the next can be different types of data get,set operation, so the benefits of the form is not Limitations of general data types, when we need to save or read complex data across one or more activity, the problem is solved.
Calling method: Meterapplication.getinstance (). GetXXX (); Read
Meterapplication.getinstance (). setxxx (X XXX);//Deposit
Public classMeterapplication extends Application {PrivateList<readytask>downloadlist; Private StaticMeterapplication instance; PrivateHashmap<string, list<readytask>>Downloadresult; PrivateList<string>unitnumlist; PrivateString Curopnum; PrivateBoolean blueconstatus; Private intcurstauts;//Current Running State@Override Public voidonCreate () {//TODO auto-generated Method StubInstance = This; Downloadlist=NewArraylist<readytask>(); Super.oncreate (); } PublicBoolean isblueconstatus () {returnBlueconstatus; } Public voidSetblueconstatus (Boolean blueconstatus) {blueconstatus=Blueconstatus; } PublicList<string>getunitnumlist () {returnunitnumlist; } Public voidSetunitnumlist (list<string>unitnumlist) {Unitnumlist=unitnumlist; } PublicHashmap<string, list<readytask>>Getdownloadresult () {returnDownloadresult; } Public voidSetdownloadresult (hashmap<string, list<readytask>>Downloadresult) {Downloadresult=Downloadresult; } Public Staticmeterapplication getinstance () {returninstance; } PublicList<readytask> Getdownloadlist () {//Download the value of list returndownloadlist; } Public voidSetdownloadlist (list<readytask>downloadlist) {downloadlist=downloadlist; } Public intgetcurstauts () {returncurstauts; } Public voidSetcurstauts (intcurstauts) {curstauts=curstauts; } PublicString Getcuropnum () {returnCuropnum; } Public voidsetcuropnum (String curopnum) {curopnum=Curopnum; } }
Android uses the application class to save the app's global data