0

I currently trying to show a progress dialog on OnclickListener of a Dialogbox since my items are taking too long to fetch from Server. I use Async task as suggested here (Android progress dialog) and this post (android problem with progress dialog) to show progress dialog The progress dialog is shown , however the code returns exception when it goes to do background that " Looper is not set". And when I set looper nothing happens.

I am not sure at this stage what is it that I am doing wrong.

public void firstMethod()
{
    final CustomObj obj = getCustomObj();//not imp

        Messages.getInstance().showAlert(MainActivity.this, "message", false, new DialogInterface.OnClickListener()
        {
            @Override
            public void onClick(DialogInterface dialog, int which)
            {
                dialog.dismiss();

            }
        }, new DialogInterface.OnClickListener()
        {

            @Override
            public void onClick(DialogInterface dialog, int which)
            {
                gotoAnotherPge(obj);

            }

        });


}   

public void gotoAnotherPge(final CustomObject obj)
{

    final ProgressDialog pd = new ProgressDialog(MainActivity.this);

     new AsyncTask<Object, Object, Boolean>()
    {

        protected void onPreExecute()
        {

            pd.setMessage(String.format(Statics.getText(MainActivity.this, R.raw.dictionary, "subscriptions_loading_unsubscribing")));
            pd.show();
        }

        protected Boolean doInBackground(Object... params)
        {       


            try{
                Looper.prepare();
                final LocalPopulator lp = new LocalPopulator(MainActivity.this, 0)
                {

                    @Override
                    public void populate()
                    {
                       List<Serializable> items = Arrays.asList(getItemHere(obj));

                        List<Serializable> listItems = new ArrayList<Serializable>();
                       listItems.addAll(items);
                        Serializable[] sItems = listItems.toArray(new Serializable[menuItems.size()]);
                        result = sItems;
                    }
                };
                showNextPage(true, 1, 0, lp);

                Looper.loop();
            }catch (Exception e){
                Log.e("tag", e.getMessage());
                /*
                 * The task failed
                 */
                return false;
            }

            return true;
        }
        protected void onPostExecute(Boolean result)
        {
            pd.dismiss();
        }


    };
    MainActivity.this.runOnUiThread (new Runnable()
    {
        @Override
        public void run()
        {

            // dismiss the progressdialog
            pd.dismiss();
        }
    });


}
Community
  • 1
  • 1
Akshay
  • 806
  • 11
  • 26
  • Well I couln't find any answer to why the Spinner (Progress Dialog) is not showing. It is somehow been put in the background for populater to finish first and then it is displayed. – Akshay May 06 '14 at 02:32
  • I made a work around that rather than using populator on main thread, I created service populater, that runs as a background task. Also now I show the Progress dialog after loading the new screen and then load the data. – Akshay May 06 '14 at 02:35

0 Answers0