我寫了一個asynctask來處理json,json結果很長(需要40-70秒才能在2G上處理)。函數僅在獲取並處理json之後執行(在postexecute()之前)。我如何更新每一秒。AsyncTask Android無法更新進度環
我refered:Android, java - Unable to update variable from asynctask
我寫了一個asynctask來處理json,json結果很長(需要40-70秒才能在2G上處理)。函數僅在獲取並處理json之後執行(在postexecute()之前)。我如何更新每一秒。AsyncTask Android無法更新進度環
我refered:Android, java - Unable to update variable from asynctask
使用AsyncHttpClient與您.gradle文件進度
過程中添加compile 'com.loopj.android:android-async-http:1.4.6'
現在創建一個服務類,並聲明它你的androidmanifest.xml
下一頁在onStartCommand在服務類:
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
Log.e(TAG, "onStartCommand");
try {
AsyncHttpClient client = new AsyncHttpClient();
client.setURLEncodingEnabled(true);
client.post(this, url, params, new AsyncHttpResponseHandler() {
@Override
public void onSuccess(int statusCode, Header[] headers, byte[] responseBody) {
// you code here after the work is done
stopService();
}
@Override
public void onFailure(int statusCode, Header[] headers, byte[] responseBody, Throwable error) {
//your code here
stopService();
}
@Override
public void onProgress(int bytesWritten, int totalSize) {
super.onProgress(bytesWritten, totalSize);
Log.e("Progess", "" + (bytesWritten/totalSize) * 100 + "%");
}
});
} catch (FileNotFoundException e) {
e.printStackTrace();
}
return super.onStartCommand(intent, flags, startId);
}
,並從活動通話
startService(serviceIntent);
使用publishProgress
從doInBackground()
像
protected Void doInBackground(Integer... params)
{
publishProgress("Loading Questions... Please wait..."+per);
...
}
發佈你的進步那是我所做的是int it? –