Spl*_*usa 3 database android dialog button android-asynctask
我目前有一个asyncTask
在preexecute开始加载栏,在后台发送一些东西到服务器,并在后执行解除对话框并启用一个按钮.但是,由于doInBackground返回null,我的post执行没有执行.我想弄明白我能做什么让postExecute运行.有任何想法吗?谢谢
码:
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");
}
}
Run Code Online (Sandbox Code Playgroud)
null
从doInBackground()
你的案子中回来是完全可以的.只需确保onPostExecute()看起来像这样:
@Override
protected void onPostExecute(Void result) {
Log.d(TAG, "p execute");
dialog.dismiss();
sendButton.setEnabled(true);
Log.d(TAG, "done executing");
}
Run Code Online (Sandbox Code Playgroud)