Shared Preferences Deleting Data When App Is Reloaded












0















I am creating my first project using Android Studio, I am aiming to create an app where you can load photos in from the phones memory and display them so people can see.



I've managed to get it working sort of how I want it to, the pictures in the gallery stay where they should do when I close out of the app and then reopen it - however if I close the app restart it and then try and add a new photo it overwrites the gallery and deletes the pictures I orginally put in. Does anyone have any ideas on how I can fix this? I tried playing with when I create the images ArrayList but that didn't help.



Code:



Main Activity



public class MainActivity extends AppCompatActivity {

private static final int PERMISSION_REQUEST = 0;
private static final int RESULT_LOAD_IMAAGE = 1;
public static final String MyPREFERENCES = "MyPrefs" ;
public static final String Name = "nameKey";

ImageView imageView;
Button uploadButton;
Button savedPhotos;
List<String> images;
String imageCreated;

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

if(Build.VERSION.SDK_INT > Build.VERSION_CODES.M && checkSelfPermission(Manifest.permission.READ_EXTERNAL_STORAGE)
!= PackageManager.PERMISSION_GRANTED){
requestPermissions(new String{Manifest.permission.READ_EXTERNAL_STORAGE}, PERMISSION_REQUEST);
}

imageView = (ImageView) findViewById(R.id.imageView);
uploadButton = (Button) findViewById(R.id.button);
savedPhotos = (Button) findViewById(R.id.button2);

SharedPreferences sharedpreferences = getSharedPreferences(MyPREFERENCES, Context.MODE_PRIVATE);
SharedPreferences.Editor editor = sharedpreferences.edit();

images = new ArrayList<>();

uploadButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent i = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(i, RESULT_LOAD_IMAAGE);
SharedPreferences sharedpreferences = getSharedPreferences(MyPREFERENCES, Context.MODE_PRIVATE);
SharedPreferences.Editor editor = sharedpreferences.edit();
editor.putString(imageCreated, "Complete");
}
});

savedPhotos.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
openPage2();
}
});


}

public void openPage2()
{
Intent intent = new Intent(this, SavedPhotos.class);
startActivity(intent);
}

@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String permissions, @NonNull int grantResults) {
switch(requestCode)
{
case PERMISSION_REQUEST:
if(grantResults[0] == PackageManager.PERMISSION_GRANTED)
{
Toast.makeText(this, "Permission Granted", Toast.LENGTH_SHORT).show();
}
else
{
Toast.makeText(this, "Permission Not Granted", Toast.LENGTH_SHORT).show();
finish();
}
}
}

@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
switch(requestCode)
{
case RESULT_LOAD_IMAAGE:
if(resultCode == RESULT_OK)
{
Uri selectedImage = data.getData();
String filePathColumn = {MediaStore.Images.Media.DATA};
Cursor cursor = getContentResolver().query(selectedImage, filePathColumn, null, null, null);
cursor.moveToFirst();
int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
String picturePath = cursor.getString(columnIndex);
cursor.close();
imageView.setImageBitmap(BitmapFactory.decodeFile(picturePath));
images.add(picturePath);
StringBuilder stringBuilder = new StringBuilder();
for(String i : images)
{
stringBuilder.append(i);
stringBuilder.append(",");
}
SharedPreferences sharedpreferences = getSharedPreferences(MyPREFERENCES, Context.MODE_PRIVATE);
SharedPreferences.Editor editor = sharedpreferences.edit();
editor.putString("images", stringBuilder.toString() );
editor.commit();

}
}
}}


And SavedPhotos



public class SavedPhotos extends AppCompatActivity {

public static final String MyPREFERENCES = "MyPrefs" ;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_saved_photos);
SharedPreferences sharedpreferences = getSharedPreferences(MyPREFERENCES, Context.MODE_PRIVATE);
SharedPreferences.Editor editor = sharedpreferences.edit();
String wordsString = sharedpreferences.getString("images", "");
String itemWords = wordsString.split(",");
List<String> items = new ArrayList<String>();
LinearLayout layout = (LinearLayout) findViewById(R.id.linear);
for(int i = 0; i < itemWords.length; i++) {
ImageView imageView = new ImageView(this);
imageView.setId(i);
imageView.setPadding(2, 2, 2, 2);
imageView.setImageBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher_foreground));
imageView.setScaleType(ImageView.ScaleType.FIT_XY);
layout.addView(imageView);
items.add(itemWords[i]);
imageView.setImageBitmap(BitmapFactory.decodeFile(items.get(i)));
}
}}


Thank you for your help :)










share|improve this question



























    0















    I am creating my first project using Android Studio, I am aiming to create an app where you can load photos in from the phones memory and display them so people can see.



    I've managed to get it working sort of how I want it to, the pictures in the gallery stay where they should do when I close out of the app and then reopen it - however if I close the app restart it and then try and add a new photo it overwrites the gallery and deletes the pictures I orginally put in. Does anyone have any ideas on how I can fix this? I tried playing with when I create the images ArrayList but that didn't help.



    Code:



    Main Activity



    public class MainActivity extends AppCompatActivity {

    private static final int PERMISSION_REQUEST = 0;
    private static final int RESULT_LOAD_IMAAGE = 1;
    public static final String MyPREFERENCES = "MyPrefs" ;
    public static final String Name = "nameKey";

    ImageView imageView;
    Button uploadButton;
    Button savedPhotos;
    List<String> images;
    String imageCreated;

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

    if(Build.VERSION.SDK_INT > Build.VERSION_CODES.M && checkSelfPermission(Manifest.permission.READ_EXTERNAL_STORAGE)
    != PackageManager.PERMISSION_GRANTED){
    requestPermissions(new String{Manifest.permission.READ_EXTERNAL_STORAGE}, PERMISSION_REQUEST);
    }

    imageView = (ImageView) findViewById(R.id.imageView);
    uploadButton = (Button) findViewById(R.id.button);
    savedPhotos = (Button) findViewById(R.id.button2);

    SharedPreferences sharedpreferences = getSharedPreferences(MyPREFERENCES, Context.MODE_PRIVATE);
    SharedPreferences.Editor editor = sharedpreferences.edit();

    images = new ArrayList<>();

    uploadButton.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
    Intent i = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
    startActivityForResult(i, RESULT_LOAD_IMAAGE);
    SharedPreferences sharedpreferences = getSharedPreferences(MyPREFERENCES, Context.MODE_PRIVATE);
    SharedPreferences.Editor editor = sharedpreferences.edit();
    editor.putString(imageCreated, "Complete");
    }
    });

    savedPhotos.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
    openPage2();
    }
    });


    }

    public void openPage2()
    {
    Intent intent = new Intent(this, SavedPhotos.class);
    startActivity(intent);
    }

    @Override
    public void onRequestPermissionsResult(int requestCode, @NonNull String permissions, @NonNull int grantResults) {
    switch(requestCode)
    {
    case PERMISSION_REQUEST:
    if(grantResults[0] == PackageManager.PERMISSION_GRANTED)
    {
    Toast.makeText(this, "Permission Granted", Toast.LENGTH_SHORT).show();
    }
    else
    {
    Toast.makeText(this, "Permission Not Granted", Toast.LENGTH_SHORT).show();
    finish();
    }
    }
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
    switch(requestCode)
    {
    case RESULT_LOAD_IMAAGE:
    if(resultCode == RESULT_OK)
    {
    Uri selectedImage = data.getData();
    String filePathColumn = {MediaStore.Images.Media.DATA};
    Cursor cursor = getContentResolver().query(selectedImage, filePathColumn, null, null, null);
    cursor.moveToFirst();
    int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
    String picturePath = cursor.getString(columnIndex);
    cursor.close();
    imageView.setImageBitmap(BitmapFactory.decodeFile(picturePath));
    images.add(picturePath);
    StringBuilder stringBuilder = new StringBuilder();
    for(String i : images)
    {
    stringBuilder.append(i);
    stringBuilder.append(",");
    }
    SharedPreferences sharedpreferences = getSharedPreferences(MyPREFERENCES, Context.MODE_PRIVATE);
    SharedPreferences.Editor editor = sharedpreferences.edit();
    editor.putString("images", stringBuilder.toString() );
    editor.commit();

    }
    }
    }}


    And SavedPhotos



    public class SavedPhotos extends AppCompatActivity {

    public static final String MyPREFERENCES = "MyPrefs" ;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_saved_photos);
    SharedPreferences sharedpreferences = getSharedPreferences(MyPREFERENCES, Context.MODE_PRIVATE);
    SharedPreferences.Editor editor = sharedpreferences.edit();
    String wordsString = sharedpreferences.getString("images", "");
    String itemWords = wordsString.split(",");
    List<String> items = new ArrayList<String>();
    LinearLayout layout = (LinearLayout) findViewById(R.id.linear);
    for(int i = 0; i < itemWords.length; i++) {
    ImageView imageView = new ImageView(this);
    imageView.setId(i);
    imageView.setPadding(2, 2, 2, 2);
    imageView.setImageBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher_foreground));
    imageView.setScaleType(ImageView.ScaleType.FIT_XY);
    layout.addView(imageView);
    items.add(itemWords[i]);
    imageView.setImageBitmap(BitmapFactory.decodeFile(items.get(i)));
    }
    }}


    Thank you for your help :)










    share|improve this question

























      0












      0








      0








      I am creating my first project using Android Studio, I am aiming to create an app where you can load photos in from the phones memory and display them so people can see.



      I've managed to get it working sort of how I want it to, the pictures in the gallery stay where they should do when I close out of the app and then reopen it - however if I close the app restart it and then try and add a new photo it overwrites the gallery and deletes the pictures I orginally put in. Does anyone have any ideas on how I can fix this? I tried playing with when I create the images ArrayList but that didn't help.



      Code:



      Main Activity



      public class MainActivity extends AppCompatActivity {

      private static final int PERMISSION_REQUEST = 0;
      private static final int RESULT_LOAD_IMAAGE = 1;
      public static final String MyPREFERENCES = "MyPrefs" ;
      public static final String Name = "nameKey";

      ImageView imageView;
      Button uploadButton;
      Button savedPhotos;
      List<String> images;
      String imageCreated;

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

      if(Build.VERSION.SDK_INT > Build.VERSION_CODES.M && checkSelfPermission(Manifest.permission.READ_EXTERNAL_STORAGE)
      != PackageManager.PERMISSION_GRANTED){
      requestPermissions(new String{Manifest.permission.READ_EXTERNAL_STORAGE}, PERMISSION_REQUEST);
      }

      imageView = (ImageView) findViewById(R.id.imageView);
      uploadButton = (Button) findViewById(R.id.button);
      savedPhotos = (Button) findViewById(R.id.button2);

      SharedPreferences sharedpreferences = getSharedPreferences(MyPREFERENCES, Context.MODE_PRIVATE);
      SharedPreferences.Editor editor = sharedpreferences.edit();

      images = new ArrayList<>();

      uploadButton.setOnClickListener(new View.OnClickListener() {
      @Override
      public void onClick(View v) {
      Intent i = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
      startActivityForResult(i, RESULT_LOAD_IMAAGE);
      SharedPreferences sharedpreferences = getSharedPreferences(MyPREFERENCES, Context.MODE_PRIVATE);
      SharedPreferences.Editor editor = sharedpreferences.edit();
      editor.putString(imageCreated, "Complete");
      }
      });

      savedPhotos.setOnClickListener(new View.OnClickListener() {
      @Override
      public void onClick(View v) {
      openPage2();
      }
      });


      }

      public void openPage2()
      {
      Intent intent = new Intent(this, SavedPhotos.class);
      startActivity(intent);
      }

      @Override
      public void onRequestPermissionsResult(int requestCode, @NonNull String permissions, @NonNull int grantResults) {
      switch(requestCode)
      {
      case PERMISSION_REQUEST:
      if(grantResults[0] == PackageManager.PERMISSION_GRANTED)
      {
      Toast.makeText(this, "Permission Granted", Toast.LENGTH_SHORT).show();
      }
      else
      {
      Toast.makeText(this, "Permission Not Granted", Toast.LENGTH_SHORT).show();
      finish();
      }
      }
      }

      @Override
      protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
      switch(requestCode)
      {
      case RESULT_LOAD_IMAAGE:
      if(resultCode == RESULT_OK)
      {
      Uri selectedImage = data.getData();
      String filePathColumn = {MediaStore.Images.Media.DATA};
      Cursor cursor = getContentResolver().query(selectedImage, filePathColumn, null, null, null);
      cursor.moveToFirst();
      int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
      String picturePath = cursor.getString(columnIndex);
      cursor.close();
      imageView.setImageBitmap(BitmapFactory.decodeFile(picturePath));
      images.add(picturePath);
      StringBuilder stringBuilder = new StringBuilder();
      for(String i : images)
      {
      stringBuilder.append(i);
      stringBuilder.append(",");
      }
      SharedPreferences sharedpreferences = getSharedPreferences(MyPREFERENCES, Context.MODE_PRIVATE);
      SharedPreferences.Editor editor = sharedpreferences.edit();
      editor.putString("images", stringBuilder.toString() );
      editor.commit();

      }
      }
      }}


      And SavedPhotos



      public class SavedPhotos extends AppCompatActivity {

      public static final String MyPREFERENCES = "MyPrefs" ;

      @Override
      protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_saved_photos);
      SharedPreferences sharedpreferences = getSharedPreferences(MyPREFERENCES, Context.MODE_PRIVATE);
      SharedPreferences.Editor editor = sharedpreferences.edit();
      String wordsString = sharedpreferences.getString("images", "");
      String itemWords = wordsString.split(",");
      List<String> items = new ArrayList<String>();
      LinearLayout layout = (LinearLayout) findViewById(R.id.linear);
      for(int i = 0; i < itemWords.length; i++) {
      ImageView imageView = new ImageView(this);
      imageView.setId(i);
      imageView.setPadding(2, 2, 2, 2);
      imageView.setImageBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher_foreground));
      imageView.setScaleType(ImageView.ScaleType.FIT_XY);
      layout.addView(imageView);
      items.add(itemWords[i]);
      imageView.setImageBitmap(BitmapFactory.decodeFile(items.get(i)));
      }
      }}


      Thank you for your help :)










      share|improve this question














      I am creating my first project using Android Studio, I am aiming to create an app where you can load photos in from the phones memory and display them so people can see.



      I've managed to get it working sort of how I want it to, the pictures in the gallery stay where they should do when I close out of the app and then reopen it - however if I close the app restart it and then try and add a new photo it overwrites the gallery and deletes the pictures I orginally put in. Does anyone have any ideas on how I can fix this? I tried playing with when I create the images ArrayList but that didn't help.



      Code:



      Main Activity



      public class MainActivity extends AppCompatActivity {

      private static final int PERMISSION_REQUEST = 0;
      private static final int RESULT_LOAD_IMAAGE = 1;
      public static final String MyPREFERENCES = "MyPrefs" ;
      public static final String Name = "nameKey";

      ImageView imageView;
      Button uploadButton;
      Button savedPhotos;
      List<String> images;
      String imageCreated;

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

      if(Build.VERSION.SDK_INT > Build.VERSION_CODES.M && checkSelfPermission(Manifest.permission.READ_EXTERNAL_STORAGE)
      != PackageManager.PERMISSION_GRANTED){
      requestPermissions(new String{Manifest.permission.READ_EXTERNAL_STORAGE}, PERMISSION_REQUEST);
      }

      imageView = (ImageView) findViewById(R.id.imageView);
      uploadButton = (Button) findViewById(R.id.button);
      savedPhotos = (Button) findViewById(R.id.button2);

      SharedPreferences sharedpreferences = getSharedPreferences(MyPREFERENCES, Context.MODE_PRIVATE);
      SharedPreferences.Editor editor = sharedpreferences.edit();

      images = new ArrayList<>();

      uploadButton.setOnClickListener(new View.OnClickListener() {
      @Override
      public void onClick(View v) {
      Intent i = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
      startActivityForResult(i, RESULT_LOAD_IMAAGE);
      SharedPreferences sharedpreferences = getSharedPreferences(MyPREFERENCES, Context.MODE_PRIVATE);
      SharedPreferences.Editor editor = sharedpreferences.edit();
      editor.putString(imageCreated, "Complete");
      }
      });

      savedPhotos.setOnClickListener(new View.OnClickListener() {
      @Override
      public void onClick(View v) {
      openPage2();
      }
      });


      }

      public void openPage2()
      {
      Intent intent = new Intent(this, SavedPhotos.class);
      startActivity(intent);
      }

      @Override
      public void onRequestPermissionsResult(int requestCode, @NonNull String permissions, @NonNull int grantResults) {
      switch(requestCode)
      {
      case PERMISSION_REQUEST:
      if(grantResults[0] == PackageManager.PERMISSION_GRANTED)
      {
      Toast.makeText(this, "Permission Granted", Toast.LENGTH_SHORT).show();
      }
      else
      {
      Toast.makeText(this, "Permission Not Granted", Toast.LENGTH_SHORT).show();
      finish();
      }
      }
      }

      @Override
      protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
      switch(requestCode)
      {
      case RESULT_LOAD_IMAAGE:
      if(resultCode == RESULT_OK)
      {
      Uri selectedImage = data.getData();
      String filePathColumn = {MediaStore.Images.Media.DATA};
      Cursor cursor = getContentResolver().query(selectedImage, filePathColumn, null, null, null);
      cursor.moveToFirst();
      int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
      String picturePath = cursor.getString(columnIndex);
      cursor.close();
      imageView.setImageBitmap(BitmapFactory.decodeFile(picturePath));
      images.add(picturePath);
      StringBuilder stringBuilder = new StringBuilder();
      for(String i : images)
      {
      stringBuilder.append(i);
      stringBuilder.append(",");
      }
      SharedPreferences sharedpreferences = getSharedPreferences(MyPREFERENCES, Context.MODE_PRIVATE);
      SharedPreferences.Editor editor = sharedpreferences.edit();
      editor.putString("images", stringBuilder.toString() );
      editor.commit();

      }
      }
      }}


      And SavedPhotos



      public class SavedPhotos extends AppCompatActivity {

      public static final String MyPREFERENCES = "MyPrefs" ;

      @Override
      protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_saved_photos);
      SharedPreferences sharedpreferences = getSharedPreferences(MyPREFERENCES, Context.MODE_PRIVATE);
      SharedPreferences.Editor editor = sharedpreferences.edit();
      String wordsString = sharedpreferences.getString("images", "");
      String itemWords = wordsString.split(",");
      List<String> items = new ArrayList<String>();
      LinearLayout layout = (LinearLayout) findViewById(R.id.linear);
      for(int i = 0; i < itemWords.length; i++) {
      ImageView imageView = new ImageView(this);
      imageView.setId(i);
      imageView.setPadding(2, 2, 2, 2);
      imageView.setImageBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher_foreground));
      imageView.setScaleType(ImageView.ScaleType.FIT_XY);
      layout.addView(imageView);
      items.add(itemWords[i]);
      imageView.setImageBitmap(BitmapFactory.decodeFile(items.get(i)));
      }
      }}


      Thank you for your help :)







      android android-studio






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 28 '18 at 23:05









      TylerR2002TylerR2002

      1




      1
























          1 Answer
          1






          active

          oldest

          votes


















          0














          I actually run to same issues before until i met a well made library and requires nothing and made my code much good looking, FastSave: https://github.com/yehiahd/FastSave-Android.






          share|improve this answer
























            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53529449%2fshared-preferences-deleting-data-when-app-is-reloaded%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            I actually run to same issues before until i met a well made library and requires nothing and made my code much good looking, FastSave: https://github.com/yehiahd/FastSave-Android.






            share|improve this answer




























              0














              I actually run to same issues before until i met a well made library and requires nothing and made my code much good looking, FastSave: https://github.com/yehiahd/FastSave-Android.






              share|improve this answer


























                0












                0








                0







                I actually run to same issues before until i met a well made library and requires nothing and made my code much good looking, FastSave: https://github.com/yehiahd/FastSave-Android.






                share|improve this answer













                I actually run to same issues before until i met a well made library and requires nothing and made my code much good looking, FastSave: https://github.com/yehiahd/FastSave-Android.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 29 '18 at 6:15









                WagedWaged

                5210




                5210
































                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53529449%2fshared-preferences-deleting-data-when-app-is-reloaded%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Contact image not getting when fetch all contact list from iPhone by CNContact

                    count number of partitions of a set with n elements into k subsets

                    A CLEAN and SIMPLE way to add appendices to Table of Contents and bookmarks