1

I can see that Google Place Picker activity can take some time to load (a few seconds) for the first time. So, I want to properly inform user that Google Place Picker is loading.

Now I'm basically creating progress dialog after clicking the button:

progressDialog = new ProgressDialog(this);
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View view) {
        FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
        fab.setEnabled(false);
        progressDialog.setMessage("Loading...");
        progressDialog.show();
        progressDialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
            public void onCancel(DialogInterface arg0) {
                //Additional question: How to cancel Place Picker?
            }
        });
        PlacePicker.IntentBuilder builder = new PlacePicker.IntentBuilder();
        try {
            startActivityForResult(builder.build(SensorDetailsActivity.this), PLACE_PICKER_REQUEST);
        } catch (GooglePlayServicesRepairableException e) {
            e.printStackTrace();
        } catch (GooglePlayServicesNotAvailableException e) {
            e.printStackTrace();
        }
    }
});
getSupportActionBar().setDisplayHomeAsUpEnabled(true);

And dismissing progress dialog when received a result:

protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == PLACE_PICKER_REQUEST) {
        if (resultCode == RESULT_OK) {
            //some code
        }
    }
    FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
    fab.setEnabled(true);
    progressDialog.dismiss();
}

The problem with that approach is that I can see the progress dialog that I created for a half of a second when I close Place Picker.

enter image description here

Note progress dialog after Place Picker closes.

Is there a better solution for this?

Vipul Asri
  • 8,903
  • 3
  • 46
  • 71
Defozo
  • 2,946
  • 6
  • 32
  • 51
  • 1
    It doesn't look like there's any way to programmatically observe an on loaded event for a PlacePicker. As a quick hack, you could just dismiss the ProgressDialog after 3 seconds using [handler.postDelayed()](http://stackoverflow.com/a/9166354/4409409) – Daniel Nugent Dec 03 '16 at 21:30

0 Answers0