Skip to content Skip to sidebar Skip to footer

Android Permanent Memory

My app does different actions deppending on the caller and some predefined values. When a call is starting to ring I need to be as fast as possible to read those preferences from t

Solution 1:

use SharedPreferences, they are like a private part of you application that will save your values permanently, untill user reinstall (clear data) application. Shared Preferences works like this

// save string in sharedPreferencesSharedPreferencessettings= PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
                    SharedPreferences.Editoreditor= settings.edit();
                    editor.putString("some_key", string); // here string is the value you want to save
                    editor.commit();                    

// restore string in sharedPreferences SharedPreferencessettings= PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
string = settings.getString("some_key", "");

Obviously you can save int boolean etc instead of string

Solution 2:

No. There's no way to tell Android to persist RAM memory. RAM memory will always be lost when the VM is shutdown.

in the Android developers site there's a good discussion on the options and approaches for permanent storage http://developer.android.com/guide/topics/data/data-storage.html

but for a quick answer is: - depending on the type and amount of data you'll probably want to use the SharedPreferences or a database (SQLite)

Solution 3:

You can use the Android Shared Preferences. http://developer.android.com/reference/android/content/SharedPreferences.html

The answer of this post is a very great solution for that. Android Shared Preferences

Post a Comment for "Android Permanent Memory"