I want have a backup on my phone, in mode OFFLINE, of my preferences, guaranteed that this preferences keep once that the app was uninstalled!!
If someone can send me a good tutorial or explicit step I will thank you!
Sorry, but this is not possible. The only places that you can write files that survive an uninstall are places where the user can delete those files.
https://stackoverflow.com/a/11135800/3750554
To reiterate what the above link says, you can use the following code to copy a folder on Android:
// If targetLocation does not exist, it will be created.
public void copyDirectory(File sourceLocation , File targetLocation)
throws IOException {
if (sourceLocation.isDirectory()) {
if (!targetLocation.exists() && !targetLocation.mkdirs()) {
throw new IOException("Cannot create dir " + targetLocation.getAbsolutePath());
}
String[] children = sourceLocation.list();
for (int i=0; i<children.length; i++) {
copyDirectory(new File(sourceLocation, children[i]),
new File(targetLocation, children[i]));
}
} else {
// make sure the directory we plan to store the recording in exists
File directory = targetLocation.getParentFile();
if (directory != null && !directory.exists() && !directory.mkdirs()) {
throw new IOException("Cannot create dir " + directory.getAbsolutePath());
}
InputStream in = new FileInputStream(sourceLocation);
OutputStream out = new FileOutputStream(targetLocation);
// Copy the bits from instream to outstream
byte[] buf = new byte[1024];
int len;
while ((len = in.read(buf)) > 0) {
out.write(buf, 0, len);
}
in.close();
out.close();
}
}
I assume that you want an app to be backed up. You can copy its location in /data/data
to wherever you choose to backup.
Alternatively, if you have a terminal emulator (if you don't, there are several on the Google Play store), you can do the POSIX way of doing it and use cp
.
cp -r /data/data/<app> <backup location>
However, CommonsWare is right. No matter where you copy your things, the user will be able to delete them.