3

So this is a tuff one. I have a activity that calls a class that call a http downloader which is the async task. What I want to do is have a please wait loading screen notification for the user while the activity is getting all the data from the web. I don't have a clue on how to get the loading screen to be called. Usually you would have it in the async task but my async task does not have a view. How to best go about doing this? Thank you for any help. My http client does have a doInBackground() so should I put the on preExecute and postExecute there? But then how would my main method which is twice removed know when its down and when its not.

What is happening is that when a button is clicked it starts the activity and starts to process all the methods, but it linger on the first activity until everything is done loading. I don't want that I want the progress dialog. It just won't show. Any thoughts on this?

NEW UPDATES Ok so now I got this set up a bit better so now at least the progress dialog now shows up. the problem is the Async task does not stop running.

MNM
  • 2,673
  • 6
  • 38
  • 73

1 Answers1

1

You should use an AsyncTask. It doesn't have to have a view, it's just a background process just like a thread.

Refer to this on how to use an AsyncTask properly with a ProgressDialog. Do your methods in the doInBackground() method of the AsyncTask.

Community
  • 1
  • 1
esfox
  • 175
  • 3
  • 11
  • Ok so I change some of my code to do as you suggested but not it will never finish running in the background. am I supposed to add like a finishing marker or something to the DoinBackground method? – MNM Apr 14 '16 at 06:13
  • Oh I don't know if this is a problem or not but it is calling a json parser which is calling a http client that is a async as well – MNM Apr 14 '16 at 06:50
  • 1
    If you want to close or stop anything after everything else has finished, do it in the `onPostExecute()` method. Everything in here occurs after everything else in the `doInBackground()` method is finished. – esfox Apr 14 '16 at 08:28
  • Yes I have one at the end of my class, but I am wondering if the other class is never being called. I am working towards that option. I have updated the code I posted above with what you suggested – MNM Apr 14 '16 at 08:41