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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T09:30:01+00:00 2026-06-11T09:30:01+00:00

I’ve read different posts that there is no way to wait for the user

  • 0

I’ve read different posts that there is no way to wait for the user to take an action when an AlertDialog is shown because it blocks the UI.

However, apps like Facebook for example displays the Gps is currently disabled. Do you want to enable gps? alert dialog and wait for the user to press yes/no.
I’m thinking that it’s possible to use 2 different activities, first one containing only the gps alert dialog, but this doesn’t seem right and definetely doens’t seem the way facebook does this.

Can anyone tell me how can i achieve this?

This is my code:

       @Override
    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    InitializeComponents();

    EnableGPSIfPossible();


        ListAsync lAsync = new ListAsync(this);
        lAsync .execute();
    }


    private void EnableGPSIfPossible()
{   
    final LocationManager manager = (LocationManager) getSystemService( Context.LOCATION_SERVICE );
     if ( !manager.isProviderEnabled( LocationManager.GPS_PROVIDER ) ) {
            buildAlertMessageNoGps();
        }
}

 private  void buildAlertMessageNoGps() {
        final AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setMessage("Yout GPS seems to be disabled, do you want to enable it?")
               .setCancelable(false)
               .setPositiveButton("Yes", new DialogInterface.OnClickListener() {
                   public void onClick(@SuppressWarnings("unused") final DialogInterface dialog, @SuppressWarnings("unused") final int id) {
                     startActivity(new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS));
                   }
               })
               .setNegativeButton("No", new DialogInterface.OnClickListener() {
                   public void onClick(final DialogInterface dialog, @SuppressWarnings("unused") final int id) {
                        dialog.cancel();
                   }
               });
        final AlertDialog alert = builder.create();
        alert.show();
    }

So, in my code the AsynTask starts imediately without waiting for the user to activate the gps. (which is a normal behaviour)

Thank you!

  • 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-11T09:30:02+00:00Added an answer on June 11, 2026 at 9:30 am

    I managed to get this to work.I got inspired by this article here which i found on stackoverlfow. http://developmentality.wordpress.com/2009/10/31/android-dialog-box-tutorial/

    I basically moved the logic that i needed to execute on the “Yes” and “Cancel” buttons of the alert Dialog.
    After performing logic needed for Yes and Cancel buttons i start the asyncronous logic execution.

    Here’s my code:

    public interface ICommand
    {
        void execute();
    }
    

    The two concrete Commands used for Enable Gps and Cancel buttons of the alert Dialog:

    public class CancelCommand implements ICommand
    {
        protected Activity m_activity;
    
        public CancelCommand(Activity activity)
        {
            m_activity = activity;
        }
    
        public void execute()
        {
            dialog.dismiss();
            //start asyncronous operation here
        }
    }
    
    
    public class EnableGpsCommand extends CancelCommand
    {
        public EnableGpsCommand( Activity activity) {
            super(activity);
        }
    
        public void execute()
        {
            // take the user to the phone gps settings and then start the asyncronous logic.
            m_activity.startActivity(new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS));
            super.execute();
        }
    }
    

    And now, from the Activity:

    //returns true if the GpsProviderIsDisabled
    //false otherwise
    private boolean EnableGPSIfPossible()
    {   
        final LocationManager manager = (LocationManager) getSystemService( Context.LOCATION_SERVICE );
        if ( !manager.isProviderEnabled( LocationManager.GPS_PROVIDER ) ) {
            buildAlertMessageNoGps();
            return true;
        }
        return false;
    }
    
    
    private  void buildAlertMessageNoGps()
    {
        final AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setMessage("Yout GPS seems to be disabled, do you want to enable it?")
            .setCancelable(false)
            .setPositiveButton("Yes", new CommandWrapper(new EnableGpsCommand(this)))
            .setNegativeButton("No", new CommandWrapper(new CancelCommand(this))); 
    
        final AlertDialog alert = builder.create();
        alert.show();
    }
    

    Now from the Activity OnCreate methodi just call:

    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.newfriendlist);
    
        InitializeComponents();
    
        if (!EnableGPSIfPossible())
        {
            //then gps is already enabled and we need to do StartFriendRetrievalAsync from here.
            //otherwise this code is being executed from the EnableGpsIfPossible() logic.
    
    
            //Asyncronous logic here.
        }
    }
    

    I really hope this will help you when you get stuck at this point :).

    Cheers

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

Sidebar

Related Questions

I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I know there's a lot of other questions out there that deal with this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into
I am doing a simple coin flipping experiment for class that involves flipping a
I need a function that will clean a strings' special characters. I do NOT
I'm trying to create an if statement in PHP that prevents a single post

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.