onpostexecute在doinnbackground成功完成后没有被调用

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(); 
       } 
      }); 
+0

请说明如何启动Asynctask .. – greenapps 2014-11-23 11:05:36

+2

它应该是'onPostExecute(long [] result)'。 – greenapps 2014-11-23 11:07:27

+0

@greenapps感谢您的回复..请检查我的编辑 – Siva 2014-11-23 11:09:37

应该onPostExecute(long [] result)

+0

可以请教育我为什么该行产生了问题? – Siva 2014-11-23 11:23:00

+0

你像'AsyncTask '一样扩展了你的类。这意味着doInBackground的返回值将是'long []'和onPostExecute的参数。正如你在onPostExecute中得到的是doInBackgroud返回的结果,类型应该是相同的。 – greenapps 2014-11-23 11:26:42