Shoshi
Shoshi

Reputation: 2254

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?

Upvotes: 5

Views: 8783

Answers (5)

Umair Mustafa
Umair Mustafa

Reputation: 218

Ιs external storage a micro SD-card and internal storage phone memory ?

First of all , you must understand that it is not necessary that external storage must be on separate SD-card and internal on phone default storage.External storage refers to the SD-card of Android devices or the equivalent partition that devices with no SD-card option.

Internal & External storage are just two separate directories which are used to save data. The internal storage is a place use to store private files which are only assessed by our Application and are deleted upon app uninstall. whereas, External storage is used to store data which your user very likely cares about, even if your app is no longer installed on the device. Examples are photos shot, images processed or sketched, code-files edited, audio files bought and so on. we can get default external storage path for storing music as follow,

Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MUSIC);

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?

To retain data after user uninstalled your application, you need to save it in External Storage. Example : usually, A photo editor app saves edited images on External storage, so that user can access that photo from gallery App and if user uninstall this application , user edited images stay on user device.

Upvotes: 0

AnV
AnV

Reputation: 2844

Ι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.

Upvotes: 1

Wolfram Rittmeyer
Wolfram Rittmeyer

Reputation: 2402

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.

Upvotes: 4

Bhavdip Sagar
Bhavdip Sagar

Reputation: 1971

You should use internal storage it was always accessed by your application,not other application could have permission to accessed.

I think you should go through the internal storage area.

Thank you

Upvotes: 0

preeya
preeya

Reputation: 169

Use Internal Storage for your purpose (as a file or as a shared pref[key-value pair] )

SD Card is not an option for you usage .

Use the android developer link which explains various storage options: http://developer.android.com/guide/topics/data/data-storage.html

Cheers, Preeya

Upvotes: -2

Related Questions