Android Async not working -


i have created asynctask. want pair bluetooth device, , after pairing should go next activity. code

public class yourtask extends asynctask<string, void, void> {     public bluetoothdevice d;     @override     protected void doinbackground(string... urls)     {         //pairdevice(d);         return null;     }     public void onpreexecute()     {         pairdevice(d);     }      @override     protected void onpostexecute(void result)     {         context context = getapplicationcontext();          int duration = toast.length_short;         charsequence text = "pairing";         toast toast = toast.maketext(context, text, duration);         toast.show();         startactivity(new intent(newdeviceactivity.this,devicesactivity.class));         finish();     } }  void pairdevice(bluetoothdevice device) {     try {          method m = device.getclass()                 .getmethod("createbond", (class[]) null);         m.invoke(device, (object[]) null);     } catch (exception e) {         log.e(tag, e.getmessage());     }  } 

the onpostexecute function gets executed before pairdevice function has finished. please help

the onpostexecute() method gets triggered after tasks in doinbackground() have been completed. in example not executing tasks in doinbackground(), resulting in onpostexecute() called immediately. move method pairdevice(bluetoothdevice device) doinbackground() method , should work.


Comments