Luka
Luka

Reputation: 255

Transparent loading activity over another activity

I'm looking for the best way to lock all the buttons and fields on my view while the application is waiting for server to respond. I created an activity that will be a little transparent and has a loading bar/spinner on it. The activity stops itself when the respons is received.

Is there any other, better way to do that. All I found on forums and such are 3-4 years old posts that use outdated/deprecated methods.

Any suggestions about how I should lock the activity and let the user know something is going on and that he/she should wait for it to finis...

Thank you

Upvotes: 0

Views: 641

Answers (2)

Shekhar Mangrule
Shekhar Mangrule

Reputation: 197

Simply you can use Android AsyncTask Class like,

  1. Initially disable all of your views (using View.setEnabled(false))

  2. Check your Server Response (Hope you are using AsyncTask class)

  3. Simply show Progress Dialog (non cancelable) until you can get the response from server (in AsyncTask's onPreExecute() method)

        progressDialog = new ProgressDialog(Activity.this);
        progressDialog.setCancelable(false);
        progressDialog.setMessage("Please Wait...");
        progressDialog.show();
    
  4. Finally, enable your all views within AsyncTask's onPostExecute() once you get Response (using View.setEnabled(true))

Upvotes: 0

NSimon
NSimon

Reputation: 5287

How about just using a ProgressDialog?

pd = new ProgressDialog(context);
            pd.setTitle("Processing...");
            pd.setMessage("Please wait.");
            pd.setCancelable(false);
            pd.setIndeterminate(true);
            pd.show();

And then when your results come up, just hide the ProgressDialog and launch your new Activity.

Upvotes: 2

Related Questions