Sorry for my English. I want to do if the loading AsyncTask is continued over a certain time (in my case, more than 1 second) everything is canceled and a message is displayed to the user "Please check the Internet", I have a message displayed, but ProgressDialog continues to run.
SendRequestAutorization sendAvtoriz = new SendRequestAutorization ();
//code
try {
sendAvtoriz.execute(
new String[]{login.getText().toString(), password.getText().toString()}).get(1, TimeUnit.SECONDS);
} catch(Exception e) {
Log.e("Avtorization", e.toString());
Toast.makeText(getApplicationContext(), "Please check the Internet", Toast.LENGTH_SHORT).show();
sendAvtoriz.cancel(true);
}
//code
private class SendRequestAutorization extends AsyncTask<String, String, String> {
ProgressDialog pDialog;
@Override
protected void onPreExecute() {
super.onPreExecute();
pDialog = new ProgressDialog(Avtorization.this);
pDialog.setMessage("Authorization");
pDialog.setCancelable(false);
pDialog.show();
}
protected String doInBackground(String... params) {
//code
return null;
}
protected void onPostExecute(String result) {
super.onPostExecute(result);
pDialog.dismiss();
}
I'm doing all right? I need another off ProgressDialog, it is right?
UDP:
Ideally, that's what I want to do: in app click button "avtorization" is showed animation loading(AsyncTask work) if loading more 5 second i display message "Please check the Internet" else i enter my profile. Now i have: in click button "avtorization" if i have internet 5 second nothing showed, showed fast loading animation and enter profile, if i have not internet and click "avtorization" nothing showed 5 secont then display "Please check the Internet"
Its my code now:
private Button logInn;
private SendRequestAutorization sendAvtoriz;
ProgressDialog pDialog;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.p_avtorization);
logInn = (Button) findViewById(R.id.createAccount);
sendAvtoriz = new SendRequestAutorization();
logInn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
pDialog = new ProgressDialog(Avtorization.this);
pDialog.setMessage("Authorization");
pDialog.setCancelable(false);
pDialog.show();
try {
sendAvtoriz.execute(
new String[]{login.getText().toString(), password.getText().toString()}).get(5, TimeUnit.SECONDS);
} catch(Exception e) {
Log.e("Avtorization", e.toString());
Toast.makeText(getApplicationContext(), "Please check the Internet", Toast.LENGTH_SHORT).show();
sendAvtoriz.cancel(true);
pDialog.dismiss();
}
}
}
//code
private class SendRequestAutorization extends AsyncTask<String, String, String> {
protected String doInBackground(String... params) {
//code
return null;
}
protected void onPostExecute(String result) {
super.onPostExecute(result);
pDialog.dismiss();
}