【发布时间】:2012-03-07 13:24:22
【问题描述】:
我试图在下面的 Asyncktask 类中查看我的 publishProgress() 调用日志。看看它是否真的在计算任何东西。就目前而言,我有一个没有更新的进度对话。
public String strAttachedFile = "";
public float nTotalSize;
public float nUploadSize;
public void Send(){
new Loadvid().execute(); // our call for asynctask
}
public class Loadvid extends AsyncTask <String,Integer,String>{
protected void onPreExecute(){
m_vwProgress.setMax((int)nTotalSize);
m_vwProgress.setMessage("Uploading, Please wait...");
m_vwProgress.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
m_vwProgress.show();
}
}
protected String doInBackground(String... params) {
boolean m_bSuccess = true;
try
{
MultipartEntity me = new MultipartEntity();
File pFp = new File(strAttachedFile);
me.addPart("videoFile", new FileBody(pFp, "video/3gpp"));
httppost.setEntity(me);
// get the total size of the file
nTotalSize = pFp.length();
HttpResponse responsePOST = client.execute(httppost);
HttpEntity resEntity = responsePOST.getEntity();
InputStream inputstream = resEntity.getContent();
StringBuilder stringbuilder = new StringBuilder();
byte data [] = new byte[512];
while ((len = inputstream.read(data))>0 )
{
StringBuilder result= stringbuilder.append(new String(data, 0, len));
String s = String.valueOf(result);
nUploadSize += len;
publishProgress((float)(nTotalSize/nUploadSize));
String myString1 = Float.toString((int)nUploadSize);
String myString2 = Float.toString((int) nTotalSize);
Log.i("Upload SIZEEEEEEEE", myString1);
Log.i("Total SIZEEEEEEEE", myString2);
}
inputstream.close();
}catch (Exception e) {
e.printStackTrace();
m_bSuccess = false;
}
if(m_bSuccess){
return "success";//Success
}
return null;//failed
}
protected void onProgressUpdate(Integer... values) {
if(m_vwProgress !=null){
m_vwProgress.setProgress(values[0]);
}
}
protected void onPostExecute(String result){
super.onPostExecute(result);
if(result==null){
// failed
if(m_vwProgress !=null)
m_vwProgress.dismiss();
return;
}
else
{
//success
if(m_vwProgress !=null)
m_vwProgress.dismiss();
}
}
【问题讨论】:
-
就像您正在做的那样:致电
Log.<level>(tag, message);。然后该消息应显示在LogCat窗口中。如果不是,您要么没有进入该方法调用,要么message-参数为空。 -
@Jave 如果我添加这个:Log.i("Show progresssss", "publishProgress()");它给了我一个错误并且不会运行。这就是为什么我想弄清楚如何显示 publishProgress()。顺便谢谢你的回答
标签: android android-asynctask logging