Why is a Intent started before an AlertDialog.Builder, even if it's coded the other way round?

Move the start image capture activity to new method, and put it to dialog's OnClickListener: builder. SetMessage(geoProtip). SetCancelable(true).

SetPositiveButton("OK", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { captureImage(); } }); private void captureImage(){ // 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); } And modify if-else: if (!geoProtipAlreadyShown) { showGeoProtip(); .... }else{ captureImage(); }.

Move your intent sending to the onclicklistener of one of the buttons of the dialog.

This is a classic gotcha for Android programmers. Basically showing the alert does not halt the execution of the code, so you have to start the intent inside an onclicklistener.

The problem is that the alert should only be shown once (on the first start). So how can I start the intent when the dialog is not shown? Do I have to source out the intent-code to a separate method and call it both via the dialog, and in the else statement?

– f. Zweig May 27 at 10:23.

I think this will be useful Dialog dlg = new AlertDialog. Builder(context) . SetTitle("TITLE") .

SetMessage("MSG") . SetPositiveButton("OK", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { //Write the intent here. } }) .create(); dlg.show().

Intent intent = new Intent(MediaStore. FromFile(new File(PATH, "tmpfile. String geoProtip = this.getResources().

Builder builder = new AlertDialog.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions