如何在android studio应用程序上使用Web应用程序数据库
问题描述:
我想将我的网络应用数据库与我的Android应用程序链接
我尝试过:
I want to link my web app database with my android app
What I have tried:
SQLiteDatabase db = mDbHelper.getReadableDatabase();
// Define a projection that specifies which columns from the database
// you will actually use after this query.
String[] projection = {
BaseColumns._ID,
FeedEntry.COLUMN_NAME_TITLE,
FeedEntry.COLUMN_NAME_SUBTITLE
};
// Filter results WHERE "title" = 'My Title'
String selection = FeedEntry.COLUMN_NAME_TITLE + " = ?";
String[] selectionArgs = { "My Title" };
// How you want the results sorted in the resulting Cursor
String sortOrder =
FeedEntry.COLUMN_NAME_SUBTITLE + " DESC";
Cursor cursor = db.query(
FeedEntry.TABLE_NAME, // The table to query
projection, // The array of columns to return (pass null to get all)
selection, // The columns for the WHERE clause
selectionArgs, // The values for the WHERE clause
null, // don't group the rows
null, // don't filter by row groups
sortOrder // The sort order
);
答
你可能会写一个拉动的服务来自webapi的数据并放入本地SQLite DB。您可以安排该服务以特定间隔执行任务异步。此外,如果服务处于联机状态,您可以尝试同时更新两个数据库。您必须小心处理同步问题。
You probably can write a service that pulls data from webapi and puts into the local SQLite DB. You can schedule that service to do the task async at certain interval. In addition, you can try to update both db at the same time, if the service is online. You have to be careful with synchronizaiton issue.