O GoConqr está de visual novo! Conte para nós o que você achou.

Notas

Sem título

Akash Agrawal Inglês 1 página

Conteúdo das notas (1)

Página 1

http://e-university.wisdomjobs.com/android/chapter-904-288/using-android-data-and-storage-apis.html

Using Android

Data and Storage APIs

Applications are about functionality

and data. In this chapter, we explore the various ways you can store, manage,

and share application data with Android. Applications can store and manage data

in different ways. For example, applications can use a combination of

application preferences, the file system, and built-in SQLite database support

to store information locally. The methods your application uses depend on your

requirements. In this chapter, you learn how to use each of these mechanisms to

store, retrieve, and interact with data.

Working with Application Preferences

Many applications need a lightweight

data storage mechanism called shared preferences for storing application state,

simple user information, configuration options, and other such information.

Android provides a simple preferences

system for storing primitive application data at the Activity level and

preferences shared across all of an application’s activities. You cannot share

preferences outside of the package. Preferences are stored as groups of

key/value pairs. The following data types are supported as preference settings:

§ Boolean values

§ Float values

§ Integer values

§ Long values

§ String values

Preference functionality can be found

in the SharedPreferences interface of the android. content package. To add

preferences support to your application, you must take the following steps:

1. Retrieve an

instance of a SharedPreferences object.

2. Create a

SharedPreferences.Editor to modify preference content.

3. Make changes to the

preferences using the Editor.

4. Commit your

changes.

Creating

Private and Shared Preferences

Individual activities can have their

own private preferences. These preferences are for the specific Activity only

and are not shared with other activities within the application. The activity

gets only one group of private preferences.

The following code retrieves the

activity’s private preferences:

import

android.content.SharedPreferences;

...

SharedPreferences settingsActivity =

getPreferences(MODE_PRIVATE);

Creating shared preferences is similar.

The only two differences are that we must name our preference set and use a

different call to get the preference instance:

import

android.content.SharedPreferences;

...

SharedPreferences settings =

getSharedPreferences(“MyCustomSharedPreferences”,

0);

You can access shared preferences by

name from any activity in the application. There is no limit to the number of

different shared preferences you can create. You can have some shared

preferences called UserNetworkPreferences and another called

AppDisplayPreferences. How you organize shared preferences is up to you, the

developer. However, you want to declare your preference name as a variable (in

a base class or header) so that you can reuse the name across multiple

activities. For example

public static final String

PREFERENCE_FILENAME = “AppPrefs”;

Searching

and Reading Preferences

Reading preferences is straightforward.

Simply retrieve the SharedPreferences instance you want to read. You can check

for a preference by name, retrieve strongly typed preferences, and register to

listen for changes to the preferences. Table describes some helpful methods in

the SharedPreferences interface.

Important

android.content.SharedPreferences Methods

Adding,

Updating, and Deleting Preferences

To change preferences, you need to open

the preference Editor, make your changes, and commit them. Table describes some

helpful methods in the Shared Preferences. Editor interface.

Important

android.content.SharedPreferences .Editor Methods

The following block of code retrieves

the activity’s private preferences, opens the preference editor, adds a long

preference called SomeLong, and saves the change:

import

android.content.SharedPreferences;

...

SharedPreferences settingsActivity = getPreferences(MODE_PRIVATE);

SharedPreferences.Editor prefEditor =

settingsActivity.edit();

prefEditor.putLong(“SomeLong”,

java.lang.Long.MIN_VALUE);

prefEditor.commit();

Finding

Preferences Data on the Android File System

Internally, application preferences are

stored as XML files. You can access the preferences file using DDMS using the

File Explorer. You find these files on the Android file system in the following

directory:

/data/data//shared_prefs/.xml

The preferences filename is the

Activity’s class name for private preferences or the name you give for the

shared preferences. Here is an example of the file contents of a simple

preference file with a preference in each data type:

Test

String

Understanding the application

preferences file format can be helpful for testing purposes. You can use Dalvik

Debug Monitor Service (DDMS) to copy the preferences files to and from the

device.

In this post we will discuss data

storage techniques in android. Android has three data storage

mechanisms

1) Preferences

2) Local Files

3) SQLite database

By default all files, databases and

preferences is restricted to the application that created them. If want to

share data with other applications you need to make use of Content Providers.

Content Providers is not a storage mechanism they provide well defined

interface for sharing private data.

Method

1: PREFERENCES

Preferences are light weight

mechanisms to store set of values in terms of key-value pairs. E.g. string,

array etc. Further preferences are of two types

1. SharedPreferences: Stores data in terms of key-value pairs and can be

accessed by application components working in the same context.

Creating

and Saving Shared Preferences:

// select your mode to be either

private or public.

int mode= Activity.MODE.PRIVATE;

// get the sharedPreference of your

context.

SharedPreferences

mySharedPreferences ; mySharedPreferences=getSharedPreferences(“Name_of_your_preference”,mode);

// retrieve an editor to modify the

shared preferences

SharedPreferences.Editor editor=

mySharedPreferences.edit();

/* now store your primitive type

values. In this case it is true, 1f and Hello! World */

editor.putBolean(“myBoolean”,true);

editor.putFloat(“myFloat”,1f);

editor.putString(“myString”,” Hello!

World”);

//save the changes that you made

editor.commit();

Retrieving

Shared Preferences

/* Now we will try to retrieve the

data saved i.e. true, 1f and Hello! World */

int mode = Activity.MODE_PRIVATE;

SharedPreferences

mySharedPreferences ;

mySharedPreferences=getSharedPreferences(“Name_of_your_preference”,mode);

/ Retrieve the saved values.

boolean mBoolean =

mySharedPreferences.getBoolean(“myBoolean”,false);

float mFloat =

mySharedPreferences.getFloat(“myFloat”, 0f);

String mSstring;

mString=

mySharedPreferences.getString(“myString”,“ ”);

/* Now mBoolean, mFloat, mString will

hold the data saved. The values false, 0f and “ “ (space) are the values that

are returned when data does not exist or cannot be retrieved*/

1. onSaveInstanceState: It designed to save the state of your activity when

it becomes eligible for termination.

Saving

Instance State

/* To save your Activity instance

variables override Activity’s onSaveInstanceState event handler and use Bundle

parameter to save instance state*/

@Override

public void

onSaveInstanceState(Bundle myBundle) {

// Retrieve the View

TextView myTextView =

(TextView)findViewById(R.id.myTextView);

String myData=

myTextView.getText().toString();

// Save its state

myBundle.putString(“Name_of_my_param

”, myData);

super.onSaveInstanceState(myBundle);

}

Restoring

Instance State

/* The Bundle that we saved

previously will be passed to onRestoreState and onCreate methods. Let’s see how

we can extract values from the Bundle*/

@Override

public void onCreate(Bundle icicle) {

super.onCreate(icicle);

setContentView(R.layout.main);

TextView myTextView =

(TextView)findViewById(R.id.myTextView);

String text = “”;

if (icicle != null &&

icicle.containsKey(“Name_of_my_param ”))

text =

icicle.getString(“Name_of_my_param ”);

myTextView.setText(text); }

Method

2: LOCAL FILES

When you do not want to use Android’s

managed mechanisms to store data you can use files directly with standard Java

I/O classes and methods.

Reading

and Writing a File

String FILE_NAME = “myFile.txt”;

// Create a new output file stream

that’s private to this application.

FileOutputStream fos =

openFileOutput(FILE_NAME, Context.MODE_PRIVATE);

// Create a new file input stream.

FileInputStream fis =

openFileInput(FILE_NAME);

These methods only support files in

the current application folder; specifying path separators will cause an

exception to be thrown.

If the filename you specify when

creating a FileOutputStream does not exist, Android will create it for you. To

append an existing file, specify the mode as Context.MODE_APPEND.

Method

3: SQLite DATABASE

Before creating and using SQLite

database we need to know few things.

1) contentValues: These objects are used to insert new

rows into the database. EachcontentValues object represents a single row.

2) Cursor: These objects are used for extracting

over query results. They act as pointer to the result set from a database

query. Cursor provides several functions navigate

through your query results like moveToFirst, moveToNext, getCount,

getColumnName etc.

3) Any databases

you create will be accessible by name to any class in the application, but not

outside the application.

4) All Android

databases are stored in the data/data//databases

folder on your device (or emulator).

5) Create a helper

class to hide complexities of adding, removing and updating data. An extension

of the SQLiteOpenHelper class, is used to simplify opening, and creating

database.

/* Below code shows how to create a

helper class and extend SQLiteOpenHelper.*/

/**Below

code snippet is taken from Pro Android Developers*/

import android.content.Context;

import android.database.*;

import android.database.sqlite.*;

import

android.database.sqlite.SQLiteDatabase.CursorFactory;

import android.util.Log;

public class MyDBAdapter {

private static final String

DATABASE_NAME = “myDatabase.db”;

private static final String

DATABASE_TABLE = “mainTable”;

private static final int

DATABASE_VERSION = 1;

// The index (key) column name for

use in where clauses.

public static final String

KEY_ID=”_id”;

// The name and column index of each

column in your database.

public static final String KEY_NAME=”name”;

public static final int NAME_COLUMN =

1;

// TODO: Create public field for each

column in your table.

// SQL Statement to create a new

database.

private static final String

DATABASE_CREATE = “create table “ +

DATABASE_TABLE + “ (“ + KEY_ID +

“ integer primary key autoincrement,

“ +

KEY_NAME + “ text not null);”;

// Variable to hold the database

instance

private SQLiteDatabase db;

// Context of the application using

the database.

private final Context context;

// Database open/upgrade helper

private myDbHelper dbHelper;

public MyDBAdapter(Context _context)

{

context = _context;

dbHelper = new myDbHelper(context,

DATABASE_NAME, null,

DATABASE_VERSION);

}

public MyDBAdapter open() throws

SQLException {

db = dbHelper.getWritableDatabase();

return this;

}

public void close() {

db.close();

}

public long insertEntry(MyObject

_myObject) {

ContentValues contentValues = new

ContentValues();

// TODO fill in ContentValues to

represent the new row

return db.insert(DATABASE_TABLE,

null, contentValues);

}

public boolean removeEntry(long

_rowIndex) {

return db.delete(DATABASE_TABLE,

KEY_ID +

“=” + _rowIndex, null) > 0;

}

public Cursor getAllEntries () {

return db.query(DATABASE_TABLE, new

String[] {KEY_ID, KEY_NAME},

null, null, null, null, null);

}

public MyObject getEntry(long

_rowIndex) {

MyObject objectInstance = new

MyObject();

// TODO Return a cursor to a row from

the database and

// use the values to populate an

instance of MyObject

return objectInstance;

}

public int updateEntry(long

_rowIndex, MyObject _myObject) {

String where = KEY_ID + “=” +

_rowIndex;

ContentValues contentValues = new

ContentValues();

// TODO fill in the ContentValue

based on the new object

return db.update(DATABASE_TABLE,

contentValues, where, null);

}

private static class myDbHelper

extends SQLiteOpenHelper {

public myDbHelper(Context context,

String name,

CursorFactory factory, int version) {

}

// Called when no database exists in

// disk and the helper class needs

// to create a new one.

@Override

public void onCreate(SQLiteDatabase

_db) {

_db.execSQL(DATABASE_CREATE);

}

// Called when there is a database

version mismatch meaning that

// the version of the database on

disk needs to be upgraded to

// the current version.

@Override

public void onUpgrade(SQLiteDatabase

_db, int _oldVersion,

int _newVersion) {

// Log the version upgrade.

Log.w(“TaskDBAdapter”, “Upgrading

from version “ +

_oldVersion + “ to “ +

_newVersion +

“, which will destroy all old data”);

// Upgrade the existing database to

conform to the new version.

// Multiple previous versions can be

handled by comparing

// _oldVersion and _newVersion

values.

// The simplest case is to drop the

old table and create a

// new one.

_db.execSQL(“DROP TABLE IF EXISTS “ +

DATABASE_TABLE);

// Create a new one.

onCreate(_db);

}

}

}

Extracting

Results from Database

// Return all rows for columns one

and three, no duplicates

String[] result_columns = new

String[] {KEY_ID, KEY_COL1, KEY_COL3};

Cursor allRows =

myDatabase.query(true, DATABASE_TABLE, result_columns,

null, null, null, null, null, null);

// Return all columns for rows where

column 3 equals a set value

// and the rows are ordered by column

5.

String where = KEY_COL3 + “=” +

requiredValue;

String order = KEY_COL5;

Cursor myResult =

myDatabase.query(DATABASE_TABLE, null, where,

null, null, null, order);

Extracting

Results from Cursor

/* Below code snippet shows how to

extract data from cursor */

int GOLD_HOARDED_COLUMN = 2;

Cursor myGold =

myDatabase.query(“GoldHoards”, null, null, null, null,

null, null);

float totalHoard = 0f;

// Make sure there is at least one

row.

if (myGold.moveToFirst()) {

// Iterate over each cursor.

do {

float hoard =

myGold.getFloat(GOLD_HOARDED_COLUMN);

totalHoard += hoard;

} while(myGold.moveToNext());

}

float averageHoard = totalHoard /

myGold.getCount();

Inserting

Rows

// Create a new row of values to

insert.

ContentValues newValues = new

ContentValues();

// Assign values for each row.

newValues.put(COLUMN_NAME, newValue);

[ ... Repeat for each column ... ]

// Insert the row into your table

myDatabase.insert(DATABASE_TABLE,

null, newValues);

Updating

Rows

// Define the updated row content.

ContentValues updatedValues = new

ContentValues();

// Assign values for each row.

updatedValues.put(COLUMN_NAME,

newValue);

[ ... Repeat for each column ... ]

String where = KEY_ID + “=” + rowId;

// Update the row with the specified

index with the new values.

myDatabase.update(DATABASE_TABLE,

updatedValues, where, null);

Deleting

Rows

myDatabase.delete(DATABASE_TABLE,

KEY_ID + “=” + rowId, null);

http://www.skill-guru.com/blog/2011/01/17/data-storage-mechanisms-in-android/

Storage Options

STORAGE QUICKVIEW

·

Use Shared Preferences for

primitive data

·

Use internal device storage for

private data

·

Use external storage for large

data sets that are not private

·

Use SQLite databases for

structured storage

IN THIS DOCUMENT

1.

Using

Shared Preferences

2.

Using

the Internal Storage

3.

Using

the External Storage

4.

Using

Databases

5.

Using a

Network Connection

SEE ALSO

1.

Content

Providers and Content Resolvers

Android provides several

options for you to save persistent application data. The solution you choose

depends on your specific needs, such as whether the data should be private to

your application or accessible to other applications (and the user) and how

much space your data requires.

Your data storage

options are the following:

Shared

Preferences

Store

private primitive data in key-value pairs.

Internal

Storage

Store

private data on the device memory.

External

Storage

Store

public data on the shared external storage.

SQLite

Databases

Store

structured data in a private database.

Network

Connection

Store

data on the web with your own network server.

Android

provides a way for you to expose even your private data to other applications —

with a content

provider. A content provider is an optional

component that exposes read/write access to your application data, subject to

whatever restrictions you want to impose. For more information about using

content providers, see the Content

Providers documentation.

Using

Shared Preferences

The SharedPreferences class

provides a general framework that allows you to save and retrieve persistent

key-value pairs of primitive data types. You can use SharedPreferences to

save any primitive data: booleans, floats, ints, longs, and strings. This data

will persist across user sessions (even if your application is killed).

User Preferences

Shared preferences are not

strictly for saving "user preferences," such as what ringtone a user

has chosen. If you're interested in creating user preferences for your

application, seePreferenceActivity,

which provides an Activity framework for you to create user preferences, which

will be automatically persisted (using shared preferences).

To get

a SharedPreferences object

for your application, use one of two methods:

·

getSharedPreferences() -

Use this if you need multiple preferences files identified by name, which you

specify with the first parameter.

·

getPreferences() -

Use this if you need only one preferences file for your Activity. Because this

will be the only preferences file for your Activity, you don't supply a name.

To

write values:

1.

Call edit() to

get a SharedPreferences.Editor.

2.

Add values with methods such as putBoolean() andputString().

3.

Commit the new values with commit()

To read

values, use SharedPreferences methods

such as getBoolean() and getString().

Here is

an example that saves a preference for silent keypress mode in a calculator:

public class Calc extends Activity {

public static final String PREFS_NAME = "MyPrefsFile";

@Override

protected void onCreate(Bundle state){

super.onCreate(state);

. . .

// Restore preferences

SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);

boolean silent = settings.getBoolean("silentMode", false);

setSilent(silent);

}

@Override

protected void onStop(){

super.onStop();

// We need an Editor object to make preference changes.

// All objects are from android.context.Context

SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);

SharedPreferences.Editor editor = settings.edit();

editor.putBoolean("silentMode", mSilentMode);

// Commit the edits!

editor.commit();

}

}

Using the Internal Storage

You can

save files directly on the device's internal storage. 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.

To

create and write a private file to the internal storage:

1.

Call openFileOutput() with

the name of the file and the operating mode. This returns aFileOutputStream.

2.

Write to the file with write().

3.

Close the stream with close().

For

example:

String FILENAME = "hello_file";

String string = "hello world!";

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

fos.write(string.getBytes());

fos.close();

MODE_PRIVATE will

create the file (or replace a file of the same name) and make it private to

your application. Other modes available are: MODE_APPEND, MODE_WORLD_READABLE,

and MODE_WORLD_WRITEABLE.

To read

a file from internal storage:

1.

Call openFileInput() and

pass it the name of the file to read. This returns a FileInputStream.

2.

Read bytes from the file with read().

3.

Then close the stream with close().

Tip: If

you want to save a static file in your application at compile time, save the

file in your project res/raw/directory.

You can open it with openRawResource(),

passing the R.raw. resource

ID. This method returns an InputStream that

you can use to read the file (but you cannot write to the original file).

Saving cache files

If

you'd like to cache some data, rather than store it persistently, you should

use getCacheDir() to

open a Filethat

represents the internal directory where your application should save temporary

cache files.

When

the device is low on internal storage space, Android may delete these cache

files to recover space. However, you should not rely on the system to clean up

these files for you. You should always maintain the cache files yourself and

stay within a reasonable limit of space consumed, such as 1MB. When the user

uninstalls your application, these files are removed.

Other useful methods

getFilesDir()

Gets

the absolute path to the filesystem directory where your internal files are

saved.

getDir()

Creates

(or opens an existing) directory within your internal storage space.

deleteFile()

Deletes

a file saved on the internal storage.

fileList()

Returns

an array of files currently saved by your application.

Using

the External Storage

Every

Android-compatible device supports a shared "external storage" that

you can use to save files. This can be a removable storage media (such as an SD

card) or an internal (non-removable) storage. Files saved to the external

storage are world-readable and can be modified by the user when they enable USB

mass storage to transfer files on a computer.

It's

possible that a device using a partition of the internal storage for the

external storage may also offer an SD card slot. In this case, the SD card is not part of the external storage and your

app cannot access it (the extra storage is intended only for user-provided

media that the system scans).

Caution: External

storage can become unavailable if the user mounts the external storage on a

computer or removes the media, and there's no security enforced upon files you

save to the external storage. All applications can read and write files placed

on the external storage and the user can remove them.

Checking media

availability

Before

you do any work with the external storage, you should always call getExternalStorageState() to

check whether the media is available. The media might be mounted to a computer,

missing, read-only, or in some other state. For example, here's how you can

check the availability:

boolean mExternalStorageAvailable = false;

boolean mExternalStorageWriteable = false;

String state = Environment.getExternalStorageState();

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

// We can read and write the media

mExternalStorageAvailable = mExternalStorageWriteable = true;

} else if (Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) {

// We can only read the media

mExternalStorageAvailable = true;

mExternalStorageWriteable = false;

} else {

// Something else is wrong. It may be one of many other states, but all we need

// to know is we can neither read nor write

mExternalStorageAvailable = mExternalStorageWriteable = false;

}

This

example checks whether the external storage is available to read and write. ThegetExternalStorageState() method

returns other states that you might want to check, such as whether the media is

being shared (connected to a computer), is missing entirely, has been removed

badly, etc. You can use these to notify the user with more information when

your application needs to access the media.

Accessing files on

external storage

If

you're using API Level 8 or greater, use getExternalFilesDir() to

open a File that

represents the external storage directory where you should save your files.

This method takes a type parameter

that specifies the type of subdirectory you want, such as DIRECTORY_MUSIC and DIRECTORY_RINGTONES (pass null to

receive the root of your application's file directory). This method will create

the appropriate directory if necessary. By specifying the type of directory,

you ensure that the Android's media scanner will properly categorize your files

in the system (for example, ringtones are identified as ringtones and not

music). If the user uninstalls your application, this directory and all its

contents will be deleted.

If

you're using API Level 7 or lower, use getExternalStorageDirectory(),

to open a File representing

the root of the external storage. You should then write your data in the

following directory:

/Android/data//files/

The is

your Java-style package name, such as "com.example.android.app".

If the user's device is running API Level 8 or greater and they uninstall your

application, this directory and all its contents will be deleted.

Hiding your files from

the Media Scanner

Include an empty file named.nomedia in your external files

directory (note the dot prefix in the filename). This will prevent Android's

media scanner from reading your media files and including them in apps like

Gallery or Music.

Saving files that should

be shared

If you

want to save files that are not specific to your application and that should not be deleted when your application is

uninstalled, save them to one of the public directories on the external

storage. These directories lay at the root of the external storage, such as Music/, Pictures/, Ringtones/,

and others.

In API

Level 8 or greater, usegetExternalStoragePublicDirectory(),

passing it the type of public directory you want, such as DIRECTORY_MUSIC,DIRECTORY_PICTURES, DIRECTORY_RINGTONES,

or others. This method will create the appropriate directory if necessary.

If

you're using API Level 7 or lower, usegetExternalStorageDirectory() to

open a File that

represents the root of the external storage, then save your shared files in one

of the following directories:

·

Music/ -

Media scanner classifies all media found here as user music.

·

Podcasts/ -

Media scanner classifies all media found here as a podcast.

·

Ringtones/ -

Media scanner classifies all media found here as a ringtone.

·

Alarms/ -

Media scanner classifies all media found here as an alarm sound.

·

Notifications/ -

Media scanner classifies all media found here as a notification sound.

·

Pictures/ -

All photos (excluding those taken with the camera).

·

Movies/ -

All movies (excluding those taken with the camcorder).

·

Download/ -

Miscellaneous downloads.

Saving cache files

If

you're using API Level 8 or greater, use getExternalCacheDir() to

open a File that

represents the external storage directory where you should save cache files. If

the user uninstalls your application, these files will be automatically

deleted. However, during the life of your application, you should manage these

cache files and remove those that aren't needed in order to preserve file

space.

If

you're using API Level 7 or lower, use getExternalStorageDirectory() to

open a File that

represents the root of the external storage, then write your cache data in the

following directory:

/Android/data//cache/

The is

your Java-style package name, such as "com.example.android.app".

Using

Databases

Android

provides full support for SQLite databases. Any databases you create

will be accessible by name to any class in the application, but not outside the

application.

The

recommended method to create a new SQLite database is to create a subclass of SQLiteOpenHelper and

override the onCreate() method,

in which you can execute a SQLite command to create tables in the database. For

example:

public class DictionaryOpenHelper extends SQLiteOpenHelper {

private static final int DATABASE_VERSION = 2;

private static final String DICTIONARY_TABLE_NAME = "dictionary";

private static final String DICTIONARY_TABLE_CREATE =

"CREATE TABLE " + DICTIONARY_TABLE_NAME + " (" +

KEY_WORD + " TEXT, " +

KEY_DEFINITION + " TEXT);";

DictionaryOpenHelper(Context context) {

super(context, DATABASE_NAME, null, DATABASE_VERSION);

}

@Override

public void onCreate(SQLiteDatabase db) {

db.execSQL(DICTIONARY_TABLE_CREATE);

}

}

You can

then get an instance of your SQLiteOpenHelper implementation

using the constructor you've defined. To write to and read from the database,

call getWritableDatabase() and getReadableDatabase(),

respectively. These both return a SQLiteDatabase object

that represents the database and provides methods for SQLite operations.

Android does not impose any

limitations beyond the standard SQLite concepts. We do recommend including an

autoincrement value key field that can be used as a unique ID to quickly find a

record. This is not required for private data, but if you implement acontent

provider, you must include a unique ID using theBaseColumns._ID constant.

You can

execute SQLite queries using the SQLiteDatabasequery() methods,

which accept various query parameters, such as the table to query, the

projection, selection, columns, grouping, and others. For complex queries, such

as those that require column aliases, you should use SQLiteQueryBuilder,

which provides several convienent methods for building queries.

Every

SQLite query will return a Cursor that

points to all the rows found by the query. The Cursor is

always the mechanism with which you can navigate results from a database query

and read rows and columns.

For

sample apps that demonstrate how to use SQLite databases in Android, see the Note

Pad and Searchable

Dictionary applications.

Database debugging

The

Android SDK includes a sqlite3 database

tool that allows you to browse table contents, run SQL commands, and perform

other useful functions on SQLite databases. See Examining

sqlite3 databases from a remote shell to

learn how to run this tool.

Using

a Network Connection

You can

use the network (when it's available) to store and retrieve data on your own

web-based services. To do network operations, use classes in the following

packages:

·

java.net.*

·

android.net.*

New Page

Informações

Descrição
Notas sobre Sem título, criado por Akash Agrawal em 05-05-2014.
Criado por
Akash Agrawal
Visualizações
15
Avaliação

Fale Conosco

Sobre o que é sua mensagem?

O que você acha do novo visual?

Você gostou?