Issue
I am trying to debug an AsyncTask within Android Studio, however the debugger is not allowing me to step into the onPostExecute()
method and I'm not sure why. I am sure that it is executing because I put a Toast that shows, however I want to debug within there and for some reason I can't. Is a reason why this would be?
private class LoadObject extends AsyncTask<Void, Void, Void> {
private ProgressDialog dialog;
private Context context;
String postAddress;
public LoadObject(Context context) {
this.context = context;
dialog = new ProgressDialog(context);
}
@Override
protected void onPreExecute() {
dialog.setMessage("Loading...");
dialog.setCanceledOnTouchOutside(false);
dialog.show();
}
@Override
protected void onPostExecute(Void result) {
Toast.makeText(context, "OnPostExecute", Toast.LENGTH_SHORT).show();
functionToExecute();
if(dialog!=null && dialog.isShowing()){
dialog.dismiss();
}
bLoaded = true;
}
@Override
protected Void doInBackground(Void... params) {
try {
postApi.postAPI(postAddress);
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
}
Solution
Try putting the line android.os.Debug.waitForDebugger();
In your onPostExecute()
method. This will wait for the debugger to attach to your separate thread, and then it will return once the debugger is attached. Then try putting a break point right after this line and it should hit.
More info here: http://developer.android.com/reference/android/os/Debug.html#waitForDebugger()
Answered By - NoChinDeluxe
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.