You cannot do this. You can do something like this
boolean flag=true;//take globally //working thread . . . catch (Exception e) { flag=false; Log.e(LOG_TAG, "CONNECTION ERROR FUNDAMO SERVER NOT RESPONDING", e); }
Once your workflow has passed, check the flag value and show Toast.
//Main Thread if(!flag) Toast.makeText(getApplicationContext(), "error server not responding " + e.getMessage(), Toast.LENGTH_SHORT).show();
Note. If you still want to show in NonUI Thread, you can use Handler or runOnUiThread()
source share