0

In my activity I did not use any asynctask. The purpose of the activity is to load data from api to sqlite database. Thus I used LoadData() on oncreate() of my activity. I want to implement progress dialogue while loading data that means time to load information. I used this

 pd = new ProgressDialog(OpeningActivity.this, ProgressDialog.STYLE_SPINNER);
    pd.setIndeterminate(true);
    pd.show(OpeningActivity.this, AppConstants.WAITTAG, AppConstants.WAITDET);

To finish progressDlg: There are few if else cases in my activity. Based on which I finished dialogue activity and called new activity intent like this

if (db.isTableExists(db3,EDU_PROVIDER_TABLE)){
                pd.dismiss();
                Intent a = new Intent(getApplicationContext(),PlaceChoiceActivity.class);//Default Activity
                a.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                //getApplicationContext().startActivity(a);
                (getApplicationContext()).startActivity(a);

                this.finish();
            }

My logcat

ctivity.OpeningActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView{41dfc8f0 V.E..... R.....ID 0,0-480,243} that was originally added here
                                                                          android.view.WindowLeaked: Activity demo.kolorob.kolorobdemoversion.activity.OpeningActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView{41dfc8f0 V.E..... R.....ID 0,0-480,243} that was originally added here

I tried to replaceOpeningActivity.this with getApplicationContext() or this or getActivity() also tried to pass context which threw exception as can not cast android.app.application can not cast to android.app.activity

user232803
  • 365
  • 6
  • 19

1 Answers1

1

Try this You are passing wrong context just pass activity context.

class ShowProgress extends AsyncTask<Void, Void, Void>{

        ProgressDialog pdialog = new ProgressDialog(MainActivity.this);


        @Override
        protected void onPreExecute() {

            pdialog.setMessage("message");
            pdialog.setTitle("title");
            pdialog.show();
        }

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

            try {
                Thread.sleep(3000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }

            return null;
        }

        @Override
        protected void onPostExecute(Void result) {

            if(pdialog != null && pdialog.isShowing()){
                pdialog.dismiss();
                 }

            insertNewData();
        }

    }
Anand Kumar Jha
  • 614
  • 9
  • 23