-1

I use a code that access HTTP service to receive login data, and before it, I tried to show a processing dialog, but it did not showed up. Then I tried to simply change the button label to tell the user to wait until data returns, but it also did not work. That's my code:

        tryingToLoginDialog = ProgressDialog.show(this, "Por Favor Aguarde", "Efetuando Login...", true);
        btn_Entrar.setText("Wait while logins...");
        btn_Entrar.invalidate();
        App.webService.Login(txtLogin.getText().toString(), txtSenha.getText().toString());
        String LoginUserData = App.webService.getUserData(); /* this method freezes the app but do not crash it cause ThreadPolicy permit all*/
        /* here some if's */
        tryingToLoginDialog.dismiss();
        btn_Entrar.setText("Login");
        btn_Entrar.invalidate();
NaN
  • 8,596
  • 20
  • 79
  • 153
  • You say you tried two different things but I can't tell if you've read: http://developer.android.com/training/basics/network-ops/index.html. Please focus on one attempt & provide code & logcat. – Morrison Chang Jun 02 '14 at 18:22
  • 2
    Have you thought about using an `AsyncTask`? Changing the thread policy is not recommended. – codeMagic Jun 02 '14 at 18:22
  • [Here is an example of setting it up](http://stackoverflow.com/questions/18898039/using-asynctask/18898105#18898105) – codeMagic Jun 02 '14 at 18:50

1 Answers1

0

You should use AsynTask. This has 4 different method doInBackground() This method run in background(not in UI Thread) In your case you can do your networking stuff here and other three methods are onProgressUpdate(), onPostExecute() and onPreExecute() run in UI Thread So you can use these function to update GUI.

You were saying you want to show dialog so setup progressdialog in onPreExecute() and do your freezing stuff in doInBackground() and use other method according to your need.

See detail here

umerk44
  • 2,797
  • 4
  • 23
  • 43
  • Not exactly a detailed guide you've got here under the term "detail", I'll rather leave this here: http://stackoverflow.com/questions/3821423/background-task-progress-dialog-orientation-change-is-there-any-100-working?lq=1 – EpicPandaForce Jun 02 '14 at 19:20
  • I think the link i mention contains enough explanation to understand AsynTask. I don't know why you discouraged that. You should review you vote, i think. – umerk44 Jun 03 '14 at 07:20