Learn Android for Free,issues for developers, mobengineers website provide complete solutions for developers issues posts.It also provides online training for android development

Monday, September 17, 2012

Data Storage in Android

Data Storage:

Android stores data in 5 ways depends on the data storage

internal storage
external storage
sqlite database
network connection

sharedpreferences: it will store the data as a key value pairs

to get SharedPreferences of ur app, use these

getSharedPreferences()  - use this if u need multiple preferences

getPreferences()- use this if u need single preference.

you can find shared preferences example here 


Internal Storage:

InputStream()- for reading the data
OutputStream()- for writing the data to the stream

1.openFileOutput() - we call the particular file.

2. write to the file with  write()
3. close the file after writing -   close()

String FILENAME= "hello_file";
Strig string="helloworld";

FileOutputStream fos=openFileOutput(FILENAME, Context.MODE_PRIVATE);



getDir()- create directory in the internal storage

deleteFile()- deletes the directory

External Storage-

boolean mExternalStorageAvilable= false;
boolean mExternalStorageWritable= false;

if(Environment.MEDIA_MOUNTED.equals(state)) {

mExternalStorageAvilable=mExternalStorageWritable= true;

mExternalStorageWritable= false;



public class namedir extends SqliteOpenHelper

private static final int DATABASE_VERSION=2;
private static final String NAME_TABL="namedir";


public void onCreate(SqliteDatabase db)
db.execSQL("CREATE TABLE NAMEDIR(id varchar(20), image BLOB, caption varchar(30), description varchar(100))");
private void VersionUpdation(SQLiteDatabase db)
public boolean CheckDataBase(String db)
SQLiteDatabase checkDB=null;

0 coment�rios:

Post a Comment

20% off

Online Training

Your Name :
Your Email: (required)
Your Message: (required)

NDTV Gadgets360

Powered by Blogger.

Recent Posts

Find Us On Facebook

Popular Posts