muraleedharan
Lurker
Hi,
I have to develope a simple chat application in android.I hv to use mysql as my backend database.But my problem is.when i am posting data on to the server,there may be too many post happends in my app.so dat,duplicate records should be inserted in my server database.For Posting data on a server,i hv to use AsyncHttpClient(loopj). Also i hv to place my code inside the runnable thread.My Problem occurs in the chat screen Page.Just check my coding structure in the following section
public class UMService extends Service {
@override
public void onCreate()
{
super.onCreate();
HandlerThread ht = new HandlerThread("nonUiThread");
ht.start(); final Handler mHandler = new Handler(ht.getLooper());
Runnable sendUpdatesToUI = new Runnable() {
public void run() {
syncSQLiteMySQLDB();
mHandler.postDelayed(this, 1000);
}
};
mHandler.postDelayed(sendUpdatesToUI, 1000)
}
Body of syncSQLiteMySQLDB() function
void syncSQLiteMySQLDB() {
String Url = prop_common.get_url()+ page.sendrequestpage;
AsyncHttpClient client = new AsyncHttpClient();
RequestParams params = new RequestParams();
if(localstoragehandler.dbSync_count()!= 0) { params.put("requestJSON",localstoragehandler.composeJSONfromSQLite());
client.post(Url,params,new AsyncHttpResponseHandler() {
@override
public void onSuccess(int statuscode, Header[] headers, byte[] byteresponse) {
try {
JSONArray arr = new JSONArray(response);
for(int i=0; i<arr.length();i++){ localstoragehandler.updateSyncStatus(Integer.parseInt(obj.get("tranid").toString()),obj.get("status").toString());
}
} catch (JSONException e) {
{
}
}
}
Note:dbSync_count() function check whether the record exists in sqllite database of phone.
I have to develope a simple chat application in android.I hv to use mysql as my backend database.But my problem is.when i am posting data on to the server,there may be too many post happends in my app.so dat,duplicate records should be inserted in my server database.For Posting data on a server,i hv to use AsyncHttpClient(loopj). Also i hv to place my code inside the runnable thread.My Problem occurs in the chat screen Page.Just check my coding structure in the following section
public class UMService extends Service {
@override
public void onCreate()
{
super.onCreate();
HandlerThread ht = new HandlerThread("nonUiThread");
ht.start(); final Handler mHandler = new Handler(ht.getLooper());
Runnable sendUpdatesToUI = new Runnable() {
public void run() {
syncSQLiteMySQLDB();
mHandler.postDelayed(this, 1000);
}
};
mHandler.postDelayed(sendUpdatesToUI, 1000)
}
Body of syncSQLiteMySQLDB() function
void syncSQLiteMySQLDB() {
String Url = prop_common.get_url()+ page.sendrequestpage;
AsyncHttpClient client = new AsyncHttpClient();
RequestParams params = new RequestParams();
if(localstoragehandler.dbSync_count()!= 0) { params.put("requestJSON",localstoragehandler.composeJSONfromSQLite());
client.post(Url,params,new AsyncHttpResponseHandler() {
@override
public void onSuccess(int statuscode, Header[] headers, byte[] byteresponse) {
try {
JSONArray arr = new JSONArray(response);
for(int i=0; i<arr.length();i++){ localstoragehandler.updateSyncStatus(Integer.parseInt(obj.get("tranid").toString()),obj.get("status").toString());
}
} catch (JSONException e) {
{
}
}
}
Note:dbSync_count() function check whether the record exists in sqllite database of phone.