1

Possible Duplicate:
Android: Save file permanently (even after clear data / uninstall)

I want to store data permanently in Android, I know to store data in database , shared preferences except from this, Is there any data Persistence in Android ? Any help will be appreciated.

Community
  • 1
  • 1
Vicky
  • 285
  • 2
  • 4
  • 13

2 Answers2

0

For permanent storage, store your data in sdCard. however, keep in mind that, even this data can be manually deleted by the user by accessing sd card. You may want to look at Storage options in android. Here you will find how to read and write in sdcard. Also, you will need to enter following permission in you manifest file:

android.permission.WRITE_EXTERNAL_STORAGE

For writing in sd-card, you may want to check this question or try:

public void onClick(View v) {
// write on SD card file data in the text box
try {
    File myFile = new File("/sdcard/MyPackageName/permanent.txt");
    myFile.createNewFile();
    FileOutputStream fOut = new FileOutputStream(myFile);
    OutputStreamWriter myOutWriter = new OutputStreamWriter(fOut);
    myOutWriter.append(write_text.getText());
    myOutWriter.close();
    fOut.close();
    Toast.makeText(getBaseContext(),
            "Done writing SD 'mysdfile.txt'",
            Toast.LENGTH_SHORT).show();
} catch (Exception e) {
    Toast.makeText(getBaseContext(), e.getMessage(),
            Toast.LENGTH_SHORT).show();
}
}// onClick
}); // btnWriteSDFile
Community
  • 1
  • 1
harshit
  • 3,788
  • 3
  • 31
  • 54
0

if you want to persist data on the sd card, you need to have the permission android.permission.WRITE_EXTERNAL_STORAGE".

also, you should open a file from an absolute location on the SD card and write to there

thepoosh
  • 12,497
  • 15
  • 73
  • 132