java - AlertDialog not working in thread Android -


When I try to print on a Bluetooth printer, I get an error about more activity on the main thread is. I tried to change it to use a thread, but then my algorithm does not work. Is there another way to do this work where I can display elitarlog? Thank you.

  Public class printersfunctions {Private Static Empty Remittance Commands (Final Reference Reference, Last String PortName, Last String Port Settings, Final Arrayist & Lt; Byte & gt; Bylist) {New Thread () { @Override public void run () {StarIoport port = null; Try {port = StarIOPort.getPort (PortName, Port Settings, 10000, Reference); Try {Thread.sleep (100); } Grip (Interrupted E) {} StarPrinterStatus Status = port.beginCheckedBlock (); If (true == status.offline) {new StarIOPortException ("a printer is offline"); } Byte [] CommandSoSendoPrinter = ConvertFormlistBitArebiteEre (bittellist); Port.writePort (commandToSendToPrinter, 0, commandToSendToPrinter.length); Port.setEndCheckedBlockTimeoutMillis (30000); Position = port.endCheckedBlock (); If (true == status.coverOpen) {new StarItortAccounts ("Printer cover is open"); } And if (true == status.receiptPaperEmpty) {new StarIOPortException ("Receipt paper is empty"); } Else if (true == status.offline) {New StarItortExtensions ("Printer is offline"); }} Hold (StarIOPortException e) {builder dialog = new AlertDialog.builder (reference); Dialog.setNegativeButton ("OK", blank); AlertDialog Warning = Dialog Create (); alert.setTitle ("failure"); Alert.setMessage (e.getMessage ()); alert.setCancelable (wrong); Alert.show (); } Finally {if (port! = Null) {try {StarIoport.releasePort (port); } Hold (StarIOPortException e) {}}}}}}. Start (); }}    

When you want to update the UI in other threads (not the main thread) You should use the handler

  the private handler handler = new handler; @ Override Protected Zero (Bundle Saved Instantstate) {Super. NET (Saved Instantstate); New thread () {@Override public void run () {handlerpost (new runall) {@Override public void run () {builder dialog = new alert.bilder (reference); Dialog.setNegativeButton ("OK", blank); Alert deiolog warning = dialog.quot (); Alert.setital ("failure"); Alert .Setmessz (E.Message ()); Warning. Setson (wrong); Alerts.show ();}}); }; }.Start(); }    

Comments

Popular posts from this blog

php - PDO bindParam() fatal error -

logging - How can I log both the Request.InputStream and Response.OutputStream traffic in my ASP.NET MVC3 Application for specific Actions? -

java - Why my included JSP file won't get processed correctly? -