We provide complete mobile and web apps development solutions

Monday, September 17, 2012

Data Storage in Android

Data Storage:

Android stores data in 5 ways depends on the data storage

sharedpreferences
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 


https://www.4shared.com/zip/AEe4gg63/SharedPreferences.html?

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);

fos.write(string.getBytes());

fos.close();



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;
}
else
if(Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)){

mExternalStorageAvilable=true;
mExternalStorageWritable= false;











 









SqliteOpenHelper



public class namedir extends SqliteOpenHelper
{

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



@override


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

Online Training

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

Powered by Blogger.

Recent Posts

Find Us On Facebook

Popular Posts