I have an activity that contains several user editable items (an EditText field, RatingBar, etc). I\'d like to prompt the user if the back/home button is pressed and change
I am doing the same thing that you do. I have one activity with a customer information (EditText for name, last name, email, ..., you know, EditText everywhere) and I used AsyncTask for that, and it works wonderfully.
@Override
public void onBackPressed()
{
// start async task for save changes.
new GuardandoContactoHilo().execute()
}
public void VolverAtras()
{
super.onBackPressed();
}
public class GuardandoContactoHilo extends AsyncTask< Void, Void, Void>
{
private ProgressDialog saving;
@Override
protected void onPreExecute()
{
super.onPreExecute();
saving = new ProgressDialog(cont);
saving.setProgressStyle(ProgressDialog.STYLE_SPINNER);
saving.setMessage("Saving customer ...");
saving.show();
}
@Override
protected void onPostExecute(Void result)
{
super.onPostExecute(result);
saving.dismiss();
VolverAtras(); // go back !!
}
@Override
synchronized protected Void doInBackground(Void... arg0)
{
// do what you want to do before come back ! for example, save data ;)
return null;
}
}