0

after a lot of research i finally decided to post the following issue here. For a college project I want to save my app settings through SharedPreferences. However whatever I do it doesn't work.

For a simple test I tried to write some testdata in my main activity's oncreate-method like this:

    SharedPreferences prefs = this.getSharedPreferences("Test", 0);
    SharedPreferences.Editor editor = prefs.edit();
    editor.putBoolean("Test", true);
    editor.commit();

When I inspect the prefs object in debug mode it shows me the path where the file is supposed to be created: /data/user/0/.../shared_prefs/Test.xml

However when I navigate there on my phone it is not there.

I am using a Galaxy S6 with Android version 7 as a test device and I have to add that I am a complete beginner at Android programming. Could you point me into a direction here?

1 Answers1

0

From Android Studio , start Android Device Monitor, go to File Explorer, and browse "/data/data/< name of your package >/shared_prefs/". You will find the XML there... and also you can copy it for inspection.

If you have a non-rooted device it's not possible to do that directly from Android Studio. However, you can access the file with adb shell as long as your application is the debug version.

adb shell
run-as your.app.id`
chmod 777 shared_prefs/your.app.id_preferences.xml
exit # return to default user
cp /data/data/your.app.id/shared_prefs/your.app.id_preferences.xml /sdcard

After that you can pull the file from /sdcard directory with adb.

As already answered here

Community
  • 1
  • 1
Benjamin
  • 7,055
  • 6
  • 40
  • 60
  • 1
    If you find yourself saying, "As already answered [here]", that's a sign that you need to flag this question as a duplicate, not answer it. In the future, please do that. – Nic Sep 27 '17 at 16:06
  • 1
    Will do. Thanks for the advice. – Benjamin Sep 27 '17 at 16:08