Tell me, please, who knows. I send email without Ineta, I still write that the message is gone. Here is the code:

private class sender_mail_async extends AsyncTask<Object, String, Boolean> { ProgressDialog WaitingDialog; @Override protected void onPreExecute() { WaitingDialog = ProgressDialog.show(SmsActivity.this, getString(R.string.data_send), getString(R.string.msg_send), true); } @Override protected void onPostExecute(Boolean result) { WaitingDialog.dismiss(); Toast.makeText(mainContext, getString(R.string.msg_sended), Toast.LENGTH_LONG).show(); ((Activity) mainContext).finish(); } @Override protected Boolean doInBackground(Object... params) { try { title = ((EditText) findViewById(R.id.screen_sendnews_et_title)).getText().toString(); text = ((EditText) findViewById(R.id.screen_sendnews_et_text)).getText().toString(); from = "*********"; where = "********"; MailSenderClass sender = new MailSenderClass("****", "*****"); sender.sendMail(title, text, from, where); } catch (Exception e) { Toast.makeText(mainContext, (R.string.error_send_msg), Toast.LENGTH_SHORT).show(); } return false; } } 
  • So you write what is sent to the post ekzekut, it is executed in any case. You need, if you have completed the operation, to hoist some flag to check it on the post. - Chad
  • But how can this be done? ... - Demendroid
  • How do you add a variable setting to a ketch and check it in a post? - Chad

1 answer 1

Attempting to call Toast inside doInBackground() meaningless - at best, nothing will work, and at worst you will get crash. doInBackground does not have access to trading.

According to the rules, you need to correctly complete the doInBackground with some error code, and in onPostExecute handle the error and give what is planned for yourself.

In general, it is absolutely kosher to check for the presence of a connection in onPreExecute() , and only if you all successfully run doInBackground() .

And yes, using Toast as a debug log is not an ice :) Logcat , for example .