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 8113569
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T02:52:14+00:00 2026-06-06T02:52:14+00:00

I have button that a user selects and I pop up a AlertDialog to

  • 0

I have button that a user selects and I pop up a AlertDialog to OK or CANCEL operation of replacing some data. The OK and CANCEL work fine after I figured out its an ASYNCH process.
And I even stop multiple clicks. However when the user presses OK , I have to save the information out to memory along with a couple of tasks. The OK process takes about three seconds, which is over the edge of impatient people. I want to throw up a indeterminate progress bar with message. However my newness to Java and android is getting in the way.
Exactly what is the ‘context’ in the code below?

public void getData(final View v)
{
     if(AlertDialogProcessing==0)
     {   
         final String title="Set Image to Wallpaper";
         final String message="Press OK to set as Wallpaper or CANCEL";
         final String ok="OK";
         final String cancel="CANCEL";
         final AlertDialog.Builder alertbox = new AlertDialog.Builder(this);
         try{
              alertbox.setMessage(message);
              alertbox.setTitle(title);
              alertbox.setPositiveButton(ok,new DialogInterface.OnClickListener(){ 
                   public void onClick(DialogInterface arg0, int arg1)
                   {  
                        Vibrate(ClickVibrate); 
                        Drawable drawable= getSun(imageSelect);  
                        ProgressDialog dialog = ProgressDialog.show(context, "Loading", "Please wait...", true);   //<<<<<<<<<<ERROR at context
                        AlertDialogProcessing=1;     
                        SaveData(drawable,1);
                        AlertDialogProcessing=0;
                        dialog.dismiss();
                        Toast.makeText(getApplicationContext(), "Data Saved.",Toast.LENGTH_LONG).show();      
                   } 
              });

              alertbox.setNegativeButton(cancel,new DialogInterface.OnClickListener(){
                   public void onClick(DialogInterface arg0, int arg1){
                        AlertDialogProcessing=0; 
                        Vibrate(ClickVibrate); 
                   } 
              });
              //alertbox.setCanceledOnTouchOutside(false); // maybe a 4.0 problem
              alertbox.show();
        } catch(Exception e){   
              //TODO Handle BadTokenException.    
        }
     }
}
  • 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-06T02:52:15+00:00Added an answer on June 6, 2026 at 2:52 am

    In the onClick() you are creating a progressDialog and you are performing the saveData() activity on the UI thread. What you can do is create an AsyncTask in the OnClick() and in its onPreExecute() show the dialog box, perform the saving action in doInBackground() and in onPostExecute() dismiss the dialog.

    The definition of Context is(as per android developer site):

    Interface to global information about an application environment.
    This is an abstract class whose implementation is provided by the
    Android system. It allows access to application-specific resources and
    classes, as well as up-calls for application-level operations such as
    launching activities, broadcasting and receiving intents, etc.

    Hope the explanation helps.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a page with some user selectable options and a button that, when
Suppose, I want to have a link or a button that when user click
I have a submit button that changes when the user hovers his mouse over
I have a activate button in my CMS that allows the user to quickly
I have a requirement that when the user clicks on [X] button of the
I have a user control that contains multiple controls (CheckBox, Button, Label...). I want
I have an NSTextField that I hide when the user presses a button. I
I have a div that I want when user click on a button slideUp
I have a page that a user selects what he wants to download, the
When a user selects the radio button that equal sales it send information to

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.