0

I am displaying progress dialog box on screen, I can not make any action until the dialog got dismissed.

How can I make some action (like Clicking on button) on screen even if progress dialog box is loading.

Loading should not stop when I click on any of button.

Here is my AsyncTask:

//My Progress Dialog

progress = ProgressDialog.show(DefaultMarketWatch.this, "",
                "Loading", true);
                

// My AsyncTask, Which executes for every 1 sec.

public class RetriveStock extends AsyncTask<Void, Void, ArrayList<User>> {

    @Override
    protected ArrayList<User> doInBackground(Void... params) {
        message += client.clientReceive(1); // Receives data from TCP socket.
        
        return null;
    }

    @Override
    protected void onCancelled() {
        super.onCancelled();
    }

    protected void onPostExecute(ArrayList<User> result) {
    progress.dismiss(); // Dismissing my progress dialog
        // My UI updations and all using "message" string.
        super.onPostExecute(result);
    }

    @Override
    protected void onPreExecute() {
        super.onPreExecute();
    }

    @Override
    protected void onProgressUpdate(Void... values) {
        super.onProgressUpdate(values);
    }

}

Please help..

enter image description here

Community
  • 1
  • 1
user2085965
  • 393
  • 2
  • 13
  • 33

3 Answers3

1

Simply use AsyncTask for getting that data. Don't use any progress dialog for showing progress.

AsyncTask will run on background not on UI thread so it will not hurdle any of your process while you are fetching or uploading any data.

AndroidHacker
  • 3,596
  • 1
  • 25
  • 45
  • Thanks for your reply, but I must show loading on screen until I receive data. – user2085965 Dec 03 '13 at 12:19
  • Doing that you can't do any stuff on screen. It is possible only when you don't use progress dialog and use AsyncTask. – AndroidHacker Dec 03 '13 at 12:21
  • I use AsyncTask in my code. I am starting progressDialog on onCreate and stoping it postExecute in AsyncTask. Even if it is loading I should do some action on screen. – user2085965 Dec 03 '13 at 12:27
  • @user2085965 You can do your action in background using thread only. – Ram Dec 03 '13 at 12:29
  • It can't be done as you want to be. It is possible if you can manage to create progress dialog of your own and set it to some place in your layout. For ex: Gmail in android loads data and show progress at end on list. Some sort of lazy loading but this might be buggy as you need to do many other stuff in it including opening a new activity. – AndroidHacker Dec 03 '13 at 12:30
  • Here action means- click on button or scrolling listView kind of things. – user2085965 Dec 03 '13 at 12:30
1

Try this...

    @Override
    protected Void doInBackground(Void... params) 
    {

         publishProgress(data to send on UI thread here );


        return null;
    }


    @Override
    protected void onProgressUpdate(String... values) {
        // TODO Auto-generated method stub
        super.onProgressUpdate(values);

        // write your UI change code here This will perform on UI therad oh Activity

        loading.setMessage("UI change");
    }
kiran boghra
  • 3,662
  • 2
  • 18
  • 23
0

If you want to do some action while loading the progress dialog means,You are violating the concept of the progress dialog.Because it is also an UI process.Better don't use the progress dialog.Use AsyncTask or runOnUIthread for your background data fetching event and do your stuff on UI.

Ram
  • 2,532
  • 4
  • 22
  • 25
  • I am doing UI operations only in onPostExecute. before enabling UI, I am closing progress dialog. Please see my code. – user2085965 Dec 03 '13 at 13:04
  • @user2085965 you told like "Even if it is loading I should do some action on screen". – Ram Dec 03 '13 at 13:09
  • I have added the screen shot. Please have a look. What I mean is, I can able to click on "currency" button even if progress dialog is loading. – user2085965 Dec 03 '13 at 13:24