Using SharedPreferences : SHA « Security « Android






Using SharedPreferences

 


package app.test;
import android.app.Activity;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.os.Bundle;
import android.util.Log;

public class Test extends Activity {

    private static final String TAG = "SavingState";
  final String INITIALIZED = "initialized";
  private String someString;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        SharedPreferences myPrefs = getPreferences(MODE_PRIVATE);
        boolean hasPreferences = myPrefs.getBoolean(INITIALIZED, false);
        if(hasPreferences) {
            Log.v(TAG, "We've been called before");
            someString = myPrefs.getString("someString", "");
        }else {
            Log.v(TAG, "First time ever being called");
            someString = "some default value";
        }
        Editor editor = myPrefs.edit();
        editor.putBoolean(INITIALIZED, true);
        editor.putString("someString", someString);
        editor.commit();
    }
}

   
  








Related examples in the same category

1.SHA-1 string
2.hmac Sha1 Digest
3.Sha1 hashes based on a given String
4.SHA1 Utils
5.Using SharedPreferences to store password
6.Drawing Shapes
7.Animated wallpaper draws a rotating wireframe shape with a choice of 2 shapes
8.Animation: shake
9.Get reference from SharedPreferences
10.Glutes shape
11.Reshaping Arabic Sentences and Text Utilities to deal with Arabic
12.Save SharedPreferences
13.Save value to SharedPreferences
14.SharedPreferences Set and get value
15.Compute the SHA-1 hash of the given byte array
16.compute SHA-1 Hash