Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Choose internal storage and external storage

What does internal storage and external storage mean in android ? Ιs external storage a micro SDcard and internal storage phone memory ? If I need to write a file for my application, which is only my application needs (the user has no work to do with this file), then where should I write my file - in internal memory or external memory?

I think, if I write my file in SDcard (external memory) then when user pull out the SDcard the application will not be able to read the file. Is it right? If it is right then writing file in external memory will not fulfill my criteria. Because, my application has to check some data in the file several times and if in that particular moment the user pulls the SDcard out, my app can't achieve its goal.

And I need to write the file permanently (but if the user uninstalls the app, then the file should be deleted). So, which way should I go?

like image 477
Shoshi Avatar asked Oct 21 '22 21:10

Shoshi


2 Answers

Have a look at this blog post about the correct way to use file storage in Android.

If you need to have access to the file all the time, internal storage is the way to go. But you shouldn't use big files in internal storage because many devices are very limited in storage space.

Files get deleted automatically on external as well as on internal storage when you use the Android built-in mechanisms to create the files in the first place. That is also explained in the post.

like image 51
Wolfram Rittmeyer Avatar answered Oct 24 '22 17:10

Wolfram Rittmeyer


Ιs external storage a micro SDcard and internal storage phone memory ?

micro SDcard and internal phone memory, both of them are external storage according to official Android docs.

If I need to write a file for my application, which is only my application needs (the user has no work to do with this file), then where should I write my file - in internal memory or external memory?

Save your files in Internal Storage.

And I need to write the file permanently (but if the user uninstalls the app, then the file should be deleted). So, which way should I go?

Save your files in Internal Storage.

Why because, according to Official Android Guide,

By default, files saved to the internal storage are private to your application and other applications cannot access them (nor can the user). When the user uninstalls your application, these files are removed.

Methods to save files in Internal Storage:

Both of them are in Context class

File getDir (String name, int mode)

File getFilesDir () 

But, note that many low end phones have limited internal memory. In those type of phones, even images captured using camera are automatically stored in SD card. You have to take care of such cases.

The Internal and External Storage terminology according to Google/official Android docs is quite different from what we think.

like image 32
AnV Avatar answered Oct 24 '22 17:10

AnV