I have the following code to print to P.O.S on Android; Before I call up the data for thermal printing, I'll call to test if the printer has paper or everything is fine with it.
PrinterDemo.getInstance(getApplicationContext(),toast,dialog).testeImpressao();
The content of the testImpression method is as follows:
public void testeImpressao() throws RemoteException {
Printer.getInstance().getStatus();
Printer.getInstance().start(new OnPrintListener.Stub() {
@Override
public void onFinish() throws RemoteException {
Log.d(TAG, "----- onFinish -----");
SendJsonPayment.eita = "deucerto";
//hideDialog();
//showToast(R.string.succeed);
}
@Override
public void onError(int error) throws RemoteException {
Log.d(TAG, "----- onError ----");
SendJsonPayment.eita = "deuerrado";
//hideDialog();
//showToast(Printer.getErrorId(error));
}
});
}
The problem is that I need to know if everything is okay before sending the print data but soon after that line "Printer.getInstance().start(new OnPrintListener.Stub()"
it exits the block and returns to the subsequent line of the test method call, which is where I test if worked out or not:
if (eita.equals("deucerto"))
And then it comes back and falls into the onError
method, that is, my condition is never satisfied, I would like to know how I can execute it immediately and introduce myself before the test happens.