2

I want to show progress bar while polyline will be drawing on the screen. I know that Polyline is drawing only in UI thread. I have tried nextcode, but this doesn't helps. There was not progress dialog

 final Handler mHandler = new Handler();

                    class shpLoading extends AsyncTask<Void, Void, Void> {
                        ProgressDialog dialog;

                        @Override
                        protected Void doInBackground(Void... params) {
                            mHandler.post(new Runnable() {
                                public void run() {
                                    googleMap.addPolyline(new PolylineOptions()
                                            .addAll(mRoutePoints)
                                            .width(3)
                                            .color(Color.RED));
                                }
                            });
                            return null;
                        }

                        @Override
                        protected void onPreExecute() {
                            Log.d("myLogs", "onPreExecute");
                            dialog = new ProgressDialog(getActivity());
                            dialog.setMessage("Kraunama...");
                            dialog.setIndeterminate(true);
                            dialog.setCancelable(false);
                            dialog.show();
                        }

                        @Override
                        protected void onPostExecute(Void result) {
                            Log.d("myLogs", "onPostExecute");
                            dialog.dismiss();
                        }
                    }

                    shpLoading shpLoading = new shpLoading();
                    shpLoading.execute();
ROMANIA_engineer
  • 54,432
  • 29
  • 203
  • 199
Kostya Khuta
  • 1,846
  • 6
  • 26
  • 48
  • 1
    A polyline does not take that long to draw on the map. the dialog is not able to come up because its happening so fast, comment out the dismiss and you will see that it shows – tyczj Jun 29 '15 at 21:13
  • but i have a lot of polylines, I want to draw exsact path from texas to california – Kostya Khuta Jun 29 '15 at 21:17
  • it still does not take that long. like I said if you dont believe me then comment out the dismiss of the dialog and you will see it shows – tyczj Jun 29 '15 at 21:19
  • I do not know exactly, but something blocked my UI thread – Kostya Khuta Jun 29 '15 at 21:19
  • I have commented it - you are right. – Kostya Khuta Jun 29 '15 at 21:20
  • No reason to use a handler inside an async task – jb15613 Jun 29 '15 at 21:22
  • 2
    The polyline has to be done on the UI thread so it is completely pointless to add the polyline in an asynctask – tyczj Jun 29 '15 at 22:03
  • This is a very old question but the reason your UI is blocked is because you are sending your polyline creation back to UI by doing this `mHandler.post()` given that `mHandler` is created by UI thread's looper – Farid Oct 26 '21 at 07:09

0 Answers0