Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

android save int

public void saveInt(int val, String key){
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(mainActivity);
    SharedPreferences.Editor editor = prefs.edit();
    editor.putInt(key, val);
    editor.apply();
}

public int getInt(String key){
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(mainActivity);
    int val = prefs.getInt(key, 0);
    return val;
}
Comment

save integer android studio

SharedPreferences mPrefs = getSharedPreferences("label", 0);
String mString = mPrefs.getString("tag", "default_value_if_variable_not_found");
Comment

save integer android studio

SharedPreferences.Editor mEditor = mPrefs.edit();
mEditor.putString("tag", value_of_variable).commit();
Comment

android save int


SharedPreferences sp = getSharedPreferences("your_prefs", Activity.MODE_PRIVATE);
SharedPreferences.Editor editor = sp.edit();
editor.putInt("your_int_key", yourIntValue);
editor.commit();

Comment

PREVIOUS NEXT
Code Example
Java :: decomposer chaine de caractère java 
Java :: sum of all numbers in array java 
Java :: java create list of strings 
Java :: groovy string to json 
Java :: paper api maven 
Java :: How to efficiently multiply two numbers represented as Strings, in Java? 
Java :: java check data type 
Java :: javafx textarea font size 
Java :: create embeds jda discord 
Java :: how to get system date in android 
Java :: java regex ip 
Java :: java join list of strings 
Java :: hibernate select count 
Java :: how to delete a object in java 
Java :: resource leak java 
Java :: spring jpa count all rows 
Java :: foreach map java 
Java :: startactivityforresult deprecated android 
Java :: java checking for null 
Java :: java int array 
Java :: Failed to determine a suitable driver class 
Java :: how to scan a string in java 
Java :: array to arraylist java 
Java :: java string remove more than one space 
Java :: Calculator Program in Java. 
Java :: java date string 
Java :: java do something after x seconds without stopping everything else 
Java :: Java List Sort Using sort() method 
Java :: java output array lists to file 
Java :: generate 5 digit random string in java 
ADD CONTENT
Topic
Content
Source link
Name
8+1 =