With the following code, the Intent is started when calling newPicture, and the Dialog is shown afterwards. What does this, and how can I change the order?
public void newPicture(View v) {
SharedPreferences settings = getPreferences(MODE_PRIVATE);
boolean geoProtipAlreadyShown = settings.getBoolean("geoProtipAlreadyShown", false);
if (!geoProtipAlreadyShown) {
showGeoProtip();
// and set the option in SharedPreferences
SharedPreferences.Editor editor = settings.edit();
editor.putBoolean("geoProtipAlreadyShown", true);
editor.commit();
}
// start the image capture activity
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(new File(PATH, "tmpfile.jpg")));
startActivityForResult(intent, IMAGE_CAPTURE);
}
private void showGeoProtip() {
String geoProtip = this.getResources().getString(R.string.protip);
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage(geoProtip).setCancelable(true).setPositiveButton("OK", null);
AlertDialog alert = builder.create();
alert.show();
}
Move the start image capture activity to new method, and put it to dialog’s OnClickListener:
And modify if-else: