android - Toast is not displaying in catch block -
Hi! When the network is down or the server is not responding, then I am trying to display a table. My message appears in the login but does not appear on the screen (not toast) I have a sample code that works fine but my code is not.
Import android.view.View.OnKeyListener; Public Class AgAppHelperMethods Extension of Activity {Personal Stable Last String LOG_TAG = Zero; Private Stable AgAppHelperMethods Example = Faucet; Public stable string varMobileNo; Public stable string varPinNo; String [] [] xmlRespone = null; Override public null on @reate (bundle saved instainstate) {super.naught (savedinstenstate); SetContentView (R.layout.agapphelpermethods); } Secure AgAppHelperMethods () {} Public Stable AgAppHelperMethods getInstance () {if (Example == Faucet) {Example = New AgAppHelperMethods (); } Return Example; } Public static string getUrl () {string URL = "https://demo.accessgroup.mobi/"; Return url; } Public string [] [] AgAppXMLParser (string parautral) {string_node, _lement; String [] [] xmlRespone = null; Try {String url = AgAppHelperMethods.getUrl () + parUrl; Url final url = new url (url); DocumentBuilderFactory DBF = DocumentBuilderFactory.newInstance (); DocumentBuilder db = dbf.newDocumentBuilder (); Document Doctor = DB Prs (new input source (final url.openstream ()); Doc.getDocumentElement () Normal () .; Node list list = doc.getElementsByTagName ("*"); _node = new string (); _length = new string (); XmlRespone = New string [list.getLength ()] [2]; For (int i = 0; i & lt; list.getLength (); i ++) {node value = list.itim (i). GetChildNodes () Item (0); _node = list.item (i) .getNodeName (); _element = value.getNodeValue (); Xml Response [i] [0] = _node; Xml Response [i] [1] = _Legment; }} Hold (exception e) {toast. GetApplicationContext, "Error server is not responding" + e.getMessage (), Toast.LENGTH_SHORT) .show (); Logs. (LOG_TAG, "Connection error does not respond to Fondombo server", e); }}} How can I show my toast message to the screen? Thank you.
You can not do this You can do something like this
Boolean flag = true; // WORLDWIDE // Take the work thread. . . Grip (exception e) {flag = false; Logs. (LOG_TAG, "Connection error does not respond to Fondombo server", e); } Once the thread that works, check the flag price and show the toast.
// Main thread if (! Flag) Toast GetApplicationContext (), "Error server does not respond" + e.getMessage (), Toast.LENGTH_SHORT) .show (); Note: If you still want to appear in the NonUI thread, then you handler or runOnUiThread ()
Comments
Post a Comment