我目前有一个asyncTask
在预执行时启动一个加载栏,在后台向服务器发送一些内容,在执行后关闭对话框并启用一个按钮。但是,由于 doInBackground 返回 null,我的后执行未执行。我试图弄清楚我能做些什么来让 postExecute 运行。有任何想法吗?谢谢
code:
class DatabaseAsync extends AsyncTask<Void,Void,Void>{
@Override
protected void onPreExecute(){
dialog = ProgressDialog.show(MainFeedActivity.this, null, "Posting...");
}
@Override
protected Void doInBackground(Void... arg0) {
Log.d(TAG, "send to databse");
SendToDatabase();
Log.d(TAG, "sent to database - DONE");
//dialog.dismiss();
//sendButton.setEnabled(true);
return null;
}
protected void onPostExecute(){
Log.d(TAG, "p execute");
dialog.dismiss();
sendButton.setEnabled(true);
Log.d(TAG, "done executing");
}
}
完全可以返回null
from doInBackground()
在你的情况下。只需确保 onPostExecute() 如下所示:
@Override
protected void onPostExecute(Void result) {
Log.d(TAG, "p execute");
dialog.dismiss();
sendButton.setEnabled(true);
Log.d(TAG, "done executing");
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)