0

Before you dismiss this question as a duplicate, just know that I saw these:

AlertDialog setmessage not working inside Asynctask

ProgressDialog does not want to update the message

Android: Progress Dialog change ProgressDialog.setMessage() while loading

Changing Progress Dialog Message While Running

But no luck.

I'm trying to update the message inside a ProgressDialog while it is showing. Yep. As simple as that.

Right now my code looks like this:

private BroadcastReceiver createMapReceiver(MapEntry entry) {
        return new BroadcastReceiver() {
            @Override
            public void onReceive(Context context, Intent intent) {

            ...

             dialogMessage = getString(R.string.maps_download_extracting)
                   .concat("\n\n")
                   .concat(getString(R.string.maps_download_suffix));

             Runnable changeMessage = () -> {
                    downloadingDialog.setMessage(dialogMessage);
                    downloadingDialog.show();
             };

             runOnUiThread(changeMessage);

             ...

        }
    };
}

But the message does not update. Everything else works as expected. What am I missing?

Luís Henriques
  • 604
  • 1
  • 10
  • 30
  • You do not need `runOnUiThread` , `onReceive` already called on mainThread . Does `onReceive` getting called or not ? – ADM May 21 '18 at 16:38
  • Yes. It is. That's what I meant by "Everything else works as expected" :p . I need the runOnUiThread because onReceive is not running on the UI thread. – Luís Henriques May 21 '18 at 16:40
  • How its not running on UI thread ? And whats the state of `downloadingDialog` just before `onReceive`? Is is showing ? – ADM May 21 '18 at 16:42
  • downloadingDialog is showing. The point is, running on UI thread or not, it does not update the message. I tried both ways. – Luís Henriques May 21 '18 at 16:47
  • You're right. onreceive() runs on the UI thread. Thanks :) Still doesn't work, though :( – Luís Henriques May 21 '18 at 16:55

1 Answers1

0

I found the solution.

I still don't know why it doesn't work, though.

Weirdly enough, I simply call another function inside the receiver, which continues the process.

Like so:

    private BroadcastReceiver createMapReceiver(MapEntry entry) {
        return new BroadcastReceiver() {
            @Override
            public void onReceive(Context context, Intent intent) {
                downloadingDialog.dismiss();
                unregisterReceiver(this);

                ...

                receiveDownloadedFile(new File(completeFilePath), entry);
            }
        };
    }



private void receiveDownloadedFile(File downloadedFile, MapEntry entry) {

   downloadingDialog.setMessage("TEST MESSAGE");

   ...

}
Luís Henriques
  • 604
  • 1
  • 10
  • 30