Issue
I have used Async Task
many times but I am facing this type of problem for the first time. I searched Stack Overflow but couldn't find any useful solution.
My issue is onPostExecute
is not getting called in Async task, All operations that are in doinbackground
are completed but control is not reaching the onPostExecute
... not able to understand the reason.
Code:
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();
}
}
}
Edit
I am calling from onclick of Image buton
deletedailydata.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
new deletedaily().execute();
}
});
Solution
It should be onPostExecute(long [] result)
.
You extended your class like AsyncTask<Void , Void, long[]>
. This means that the return value of doInBackground will be long[]
and the parameter of onPostExecute also. As what you get in onPostExecute is the result returned by doInBackgroud the type should be the same.
Answered By - greenapps
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.