How to backup/restore Uri for reuse after app restart?
We have a Uri from a file picker and use it to save some data to the file.
Now we want to backup this Uri (file path)
<code>...
myPrefsEdit.putString("uriLogFile", selectedFileUri.toString());
myPrefsEdit.commit();
</code>
<code>...
myPrefsEdit.putString("uriLogFile", selectedFileUri.toString());
myPrefsEdit.commit();
</code>
...
myPrefsEdit.putString("uriLogFile", selectedFileUri.toString());
myPrefsEdit.commit();
When the application is restarted, we want to restore the Uri (file path). But how to do it? This is not working:
<code>...
String path = myPrefs.getString("uriLogFile", "");
selectedFileUri = Uri.fromFile(new File(path));
</code>
<code>...
String path = myPrefs.getString("uriLogFile", "");
selectedFileUri = Uri.fromFile(new File(path));
</code>
...
String path = myPrefs.getString("uriLogFile", "");
selectedFileUri = Uri.fromFile(new File(path));
and this is not functional either
<code>selectedFileUri = Uri.parse(path)
</code>
<code>selectedFileUri = Uri.parse(path)
</code>
selectedFileUri = Uri.parse(path)
Apparently it’s not enough to store only the path to the file?
New contributor
PaulHook is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.