Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9217063
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T02:33:27+00:00 2026-06-18T02:33:27+00:00

I have a class in which a button is pressed it shows a dialog

  • 0

I have a class in which a button is pressed it shows a dialog box. This box has two buttons YES,NO. When i click YES i want to call async task to update some values in DB. I tried this but it Gives me Looper.prepare() error. Searched all over SO and GOogle but no solution. Does any1 have any ideas?

Thanx

bttnSync.setOnClickListener(new OnClickListener() {

        public void onClick(View v) {

            if (isOnline()) {
                AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(
                        MainPage.this);
                alertDialogBuilder.setTitle("Syncing all data....!!");
                alertDialogBuilder
                        .setMessage(
                                "Are you sure you want to Sync all the data?")
                        .setCancelable(false)
                        .setPositiveButton("Yes",
                                new DialogInterface.OnClickListener() {
                                    public void onClick(
                                            DialogInterface dialog, int id) {

                                         //call();

                                        new CountDownTask().execute();

                                        MainPage.this.finish();
                                        Intent i = new Intent(
                                                "com.example.collegesoft.MainPage");
                                        startActivity(i);
                                    }
                                })
                        .setNegativeButton("No",
                                new DialogInterface.OnClickListener() {
                                    public void onClick(
                                            DialogInterface dialog, int id) {
                                        dialog.cancel();
                                    }
                                });

                AlertDialog alertDialog = alertDialogBuilder.create();

                // show it
                alertDialog.show();
            } else {
                AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(
                        MainPage.this);
                alertDialogBuilder.setTitle("No Internet Connection!!");
                alertDialogBuilder
                        .setMessage(
                                "Device is not connected to the Internet or the connection is slow.")
                        .setCancelable(false)

                        .setNegativeButton("Cancel",
                                new DialogInterface.OnClickListener() {
                                    public void onClick(
                                            DialogInterface dialog, int id) {
                                        dialog.cancel();
                                    }
                                });

                AlertDialog alertDialog = alertDialogBuilder.create();

                // show it
                alertDialog.show();
            }

        }
    });


private class CountDownTask extends AsyncTask<Void, Integer, Void> {

    protected void onPreExecute() {
        progressDialog = ProgressDialog.show(MainPage.this, "Loading...",
                "Loading application , please wait...", false, false);

    }

    protected Void doInBackground(Void... params) {
        call();


        return null;
    }

    protected void onProgressUpdate(Integer... values) {
        progressDialog.setProgress(values[0]);
    }

    protected void onPostExecute(Void result) {
        progressDialog.dismiss();
    }

}


   01-31 10:41:37.575: E/AndroidRuntime(9038): FATAL EXCEPTION: AsyncTask #1
   01-31 10:41:37.575: E/AndroidRuntime(9038): java.lang.RuntimeException: An error   occured while executing doInBackground()
   01-31 10:41:37.575: E/AndroidRuntime(9038):  at android.os.AsyncTask$3.done(AsyncTask.java:278)
     01-31 10:41:37.575: E/AndroidRuntime(9038):    at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273)
      01-31 10:41:37.575: E/AndroidRuntime(9038):   at java.util.concurrent.FutureTask.setException(FutureTask.java:124)
     01-31 10:41:37.575: E/AndroidRuntime(9038):    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307)
    01-31 10:41:37.575: E/AndroidRuntime(9038):     at java.util.concurrent.FutureTask.run(FutureTask.java:137)
     01-31 10:41:37.575: E/AndroidRuntime(9038):    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
       01-31 10:41:37.575: E/AndroidRuntime(9038):  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
     01-31 10:41:37.575: E/AndroidRuntime(9038):    at java.lang.Thread.run(Thread.java:856)
    01-31 10:41:37.575: E/AndroidRuntime(9038): Caused by: java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()
     01-31 10:41:37.575: E/AndroidRuntime(9038):    at android.os.Handler.<init>(Handler.java:121)
     01-31 10:41:37.575: E/AndroidRuntime(9038):    at android.app.Activity.<init>(Activity.java:735)
     01-31 10:41:37.575: E/AndroidRuntime(9038):    at com.example.collegesoft.SyncData.<init>(SyncData.java:22)
     01-31 10:41:37.575: E/AndroidRuntime(9038):    at com.example.collegesoft.MainPage.call(MainPage.java:259)
     01-31 10:41:37.575: E/AndroidRuntime(9038):    at com.example.collegesoft.MainPage$CountDownTask.doInBackground(MainPage.java:284)
     01-31 10:41:37.575: E/AndroidRuntime(9038):    at com.example.collegesoft.MainPage$CountDownTask.doInBackground(MainPage.java:1)
       01-31 10:41:37.575: E/AndroidRuntime(9038):  at android.os.AsyncTask$2.call(AsyncTask.java:264)
      01-31 10:41:37.575: E/AndroidRuntime(9038):   at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
   01-31 10:41:37.575: E/AndroidRuntime(9038):  ... 4 more
    01-31 10:41:43.966: E/WindowManager(9038): Activity  com.example.collegesoft.MainPage has leaked window  com.android.internal.policy.impl.PhoneWindow$DecorView@41753818 that was originally added  here
     01-31 10:41:43.966: E/WindowManager(9038): android.view.WindowLeaked: Activity com.example.collegesoft.MainPage has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@41753818 that was originally added here
     01-31 10:41:43.966: E/WindowManager(9038):     at android.view.ViewRootImpl.<init>(ViewRootImpl.java:383)
    01-31 10:41:43.966: E/WindowManager(9038):  at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:279)
    01-31 10:41:43.966: E/WindowManager(9038):  at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:215)
  01-31 10:41:43.966: E/WindowManager(9038):    at android.view.WindowManagerImpl$CompatModeWrapper.addView(WindowManagerImpl.java:140)
    01-31 10:41:43.966: E/WindowManager(9038):  at android.view.Window$LocalWindowManager.addView(Window.java:537)
     01-31 10:41:43.966: E/WindowManager(9038):     at android.app.Dialog.show(Dialog.java:278)
   01-31 10:41:43.966: E/WindowManager(9038):   at android.app.ProgressDialog.show(ProgressDialog.java:116)
    01-31 10:41:43.966: E/WindowManager(9038):  at android.app.ProgressDialog.show(ProgressDialog.java:104)
     01-31 10:41:43.966: E/WindowManager(9038):     at com.example.collegesoft.MainPage$CountDownTask.onPreExecute(MainPage.java:278)
     01-31 10:41:43.966: E/WindowManager(9038):     at android.os.AsyncTask.executeOnExecutor(AsyncTask.java:561)
    01-31 10:41:43.966: E/WindowManager(9038):  at android.os.AsyncTask.execute(AsyncTask.java:511)
   01-31 10:41:43.966: E/WindowManager(9038):   at com.example.collegesoft.MainPage$3$1$1.run(MainPage.java:82)
       01-31 10:41:43.966: E/WindowManager(9038):   at android.os.Handler.handleCallback(Handler.java:605)
       01-31 10:41:43.966: E/WindowManager(9038):   at android.os.Handler.dispatchMessage(Handler.java:92)
    01-31 10:41:43.966: E/WindowManager(9038):  at android.os.Looper.loop(Looper.java:137)
      01-31 10:41:43.966: E/WindowManager(9038):    at android.app.ActivityThread.main(ActivityThread.java:4514)
   01-31 10:41:43.966: E/WindowManager(9038):   at java.lang.reflect.Method.invokeNative(Native Method)
   01-31 10:41:43.966: E/WindowManager(9038):   at java.lang.reflect.Method.invoke(Method.java:511)
  01-31 10:41:43.966: E/WindowManager(9038):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:790)
   01-31 10:41:43.966: E/WindowManager(9038):   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:557)
     01-31 10:41:43.966: E/WindowManager(9038):     at dalvik.system.NativeStart.main(Native Method)

My call() method ….

protected void call() {
    Log.d(TAG,"Call Called");
    myDbHelper = new DatabaseHelper(MainPage.this);

    try {

        myDbHelper.openDataBase();

    } catch (SQLException sqle) {

        throw sqle;

    }

    Cursor c = myDbHelper.getAllStudentFromMainTable();

    Log.d(TAG, "Cursor : " + c.getColumnCount());

    //new CountDownTask().execute();
    new SyncData().sendJson(c, myDbHelper, MainPage.this);

    //c.close();

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T02:33:28+00:00Added an answer on June 18, 2026 at 2:33 am

    You can create a Handler at your activity and then use it to post what you need to do.

    Example:

    public void onAvatarChange(View v) {
       final Handler uiHandler = new Handler();
    
       //Build dialog....
       OnclickListener onYes = new OnClickListener {
           public void onClick(View v) {
                uiHanlder.post(new Runnable() {
                     public void run() {
                         //Do whatever you want here...
                         //You will have looper.prepare here, as it will run on main thread as soon as possible.
                     }
                }
           }
       }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have few buttons of which each button is assigned a class with a
I have a actionSave class which extends AbstractAction.I use it for save button. somewhere
I have crated a class which extends the ListFragment . I have one button
I have class A which extends the Activity class. This class is in package
I have class Employee which is something like this. class Emp { int EmpID;
I have a simple button which will open up the AddStation form (this button
I have written the below code which has a text-field and a button. as
I have a class which extends Activity this class job is to get some
I have an Activity ( Main ) which shows tabs like this: private void
I have two buttons in one class and those buttons send you to the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.