开发者

store data locally when no network access in android

I want to send data in my database using httppostrequest.But when there is no network access how to store data locally and when my 开发者_如何学Goapplication receives network post it to server


In a database might be a good solution. The notepad tutorial is a decent introduction to programming with databases in an Android app.

Also, it's worth spending the time necessary to read and become familiar with the topics covered in http://developer.android.com/guide/topics/data/data-storage.html


Use this to check for connection:

public boolean isOnline() {
 ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
 return cm.getActiveNetworkInfo().isConnectedOrConnecting();

}

On storing data to SQLite check this tutorial:

http://p-xr.com/android-tutorial-simple-but-persistent-data-storage/


I approve Mark Mooibroek response and advise to use some DB helper instead of raw SQLite, as it needs a lot of boilerplate code. Last time I was glad with using Realm database library. It's faster than SQLite in terms of both efficiency and coding time.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜