save the current data of the arraylist when closing the app and retrieve it upon returning android -
I'm new to Android, and I have an array list that stores data from user input and I Then want to save when the user closes the app and retrieves it when the user re-opens the app then my code is
string getInput = inputText.getText (). toString (); If (getInput) getInput.equals ("")) {toast. Make text (getBaseContext), "item may have been added previously or not, empty", toast. LNNGH_LOG). Show (); } And {addArray.add (getInput); Toast. Make text (getBaseContext), "item added", toast.lNGTH_LONG). Show (); ArrayAdapter & LT; String & gt; Adapters = new arreptopter & lt; String & gt; (Main activity. This, Android R. outout. Simple_LiLink_Item_multiplay_choice, adare); Find show = (LISTviewView) VVBIID (RID. Show.setAdapter (adapter); ((EditText) FindUBID (RID.Edit Input)) Settext ("");
You can use PreferenceManager;
Here is an example: The app is opened while saving passwords and receiving it
Public class SavedPreference {static last string PREF_USER_NAME = "username"; Fixed final string PREF_PASS = "password"; Static Shared References Share References (Reference CT) {Return PreferenceManager.getDefaultSharedPreferences (ct); } Public Static Zero SetUsernName (Reference CTX, String Username) {Editor Editor = Meet -Share Prices (CTX). Edit (); Editor.putString (PREF_USER_NAME, username); editor.commit (); } Public Static Zero Delete Saved References (Reference CTX) {Editor Editor = Meet -Share-Theme (CTX). Edit (); Editor.clear (); editor.commit (); } Public stable string getUserName (reference CTX) {return getSharedPreferences (ctx) .getString (PREF_USER_NAME, ""); } }
When you want to see that a certain string is saved from the execution time of the app
If (SavedPreference.getUserName (this) .length () == 0) {// string not found} and {// string found}
अधिकतम तीन युगल नमूना कोड ढूँढना
ReplyDeleteFinding the maximum of three doubles