在后台从android执行.php文件的最佳方法是什么?我需要它来刷新 mysql 数据库中的用户活动时间。因此,如果用户单击一个按钮,则应在数据库中使用他的最后一个活动数据时间完成一个新条目。
我应该像那样使用异步任务吗?
private class UpdateUser extends AsyncTask<String, String, String> {
@Override
protected void onPreExecute() {
super.onPreExecute();
//I don't like to have a dialog. This hinds the user while he is using the app
}
/**
* Creating product
* */
protected String doInBackground(String... args) {
jsonParser = new JSONParser();
String BENUTZER_NAME = actual_tUsername;
// Building Parameters
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("BENUTZER_NAME", BENUTZER_NAME));
//Call the php file defined as string which is updating the users last online datetime
JSONObject json = jsonParser.makeHttpRequest(url_update_activetime,
"POST", params);
if(json == null){
Log.v("NULL", "NULL");
}
return null;
}
/**
* After completing background task Dismiss the progress dialog
* **/
protected void onPostExecute(String file_url) {
}
}
还是我应该更好地使用 runOnUiThread?或者有没有更好的方法来解决这个问题??
提前致谢!