onpostexecute在doinnbackground成功完成后没有被调用
问题描述:
我多次使用Async Task
,但第一次遇到这种类型的问题。搜索SO
,但找不到解决我的问题的任何有用的解决方案。onpostexecute在doinnbackground成功完成后没有被调用
我的问题是onPostExecute
没有在异步任务中调用,所有在doinbackground
中的操作都已完成,但控制未达到onPostExecute
...无法理解原因。
请帮帮我。
谢谢你的时间。
代码:
public class deletedaily extends AsyncTask<Void , Void, long[]>{
ProgressDialog pd;
long resultdelete;
protected void onPreExecute(){
pd=new ProgressDialog(StockDetail.this);
if(pd!=null){
pd.setMessage("Deleting data.....please wait");
pd.show();
}
}
protected long[] doInBackground(Void... params) {
// TODO Auto-generated method stub
try{
Database.getInstance(getApplicationContext()).getWritableDatabase().beginTransaction();
resultdelete = Database.getInstance(getApplicationContext()).getWritableDatabase().delete(st.tablename, st.column2 + "=? AND " + st.column3 + "=?", new String[] {getdailydate.toString(),stockname});
Database.getInstance(getApplicationContext()).getWritableDatabase().setTransactionSuccessful();
new popdailydata().execute(); //here calling list view to populate after deletion
}
catch(Exception dailydeleteerror){}
finally{
Database.getInstance(getApplicationContext()).getWritableDatabase().endTransaction();
}
return new long[] {resultdelete};
}
protected void onPostExecute(long result){
System.out.println("postexecute entered");
if(pd!=null){
pd.dismiss();
}
if(result!=-1){
Toast.makeText(getApplicationContext(),"Date deleted from your portfolio", Toast.LENGTH_LONG).show();
}
else{
Toast.makeText(getApplicationContext(),"Failed to delete ....try again", Toast.LENGTH_LONG).show();
}
}
}
编辑---------------------------------
我从图片布顿的的onclick调用
deletedailydata.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
new deletedaily().execute();
}
});
请说明如何启动Asynctask .. – greenapps 2014-11-23 11:05:36
它应该是'onPostExecute(long [] result)'。 – greenapps 2014-11-23 11:07:27
@greenapps感谢您的回复..请检查我的编辑 – Siva 2014-11-23 11:09:37