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.
精彩评论