package com.example.preferencedemo;

import android.content.SharedPreferences;
import android.os.Bundle;
import android.util.Log;

import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {
    private SharedPreferences settings;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);


        if (settings == null) {
            settings = getSharedPreferences("MY_PREFERENCE", MODE_PRIVATE);
        }


        //*****************************************************************
        //  CREATE DATA IN PREFERENCE
        //*****************************************************************
        SharedPreferences.Editor preference_editor = settings.edit();

        preference_editor.putString("USER_NAME", "karan");
        preference_editor.putString("PASSWORD", "karan");

        preference_editor.commit();
        //*****************************************************************
        //  DISPLAY VALUE IN PREFERENCES
        //*****************************************************************
        Log.v("PREFERENCE_USER_NAME", settings.getString("USER_NAME", ""));
        Log.v("PREFERENCE_PASSWORD", settings.getString("PASSWORD", ""));

    }
}




























Posted By  -  Karan Gupta
 
Posted On  -  Wednesday, September 04, 2019

Query/Feedback


Your Email Id  
 
Subject 
 
Query/FeedbackCharacters remaining 250