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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T21:37:21+00:00 2026-06-04T21:37:21+00:00

I have some troubles in my Android app. I need to start an intent

  • 0

I have some troubles in my Android app. I need to start an intent when another intent has finished. The problem is that both intents are launched at the same time (i don’t know why). Here is my code:

In this dialog i ask if the user wants to take a photo before send an email (and of course i want to send the email with the photo). Ok?

private Dialog comprobarFoto() {
        AlertDialog.Builder builder = new AlertDialog.Builder(this); 

        builder.setMessage("¿Desea adjuntar una foto con este mensaje de su posición actual?");
        builder.setPositiveButton("Si", new OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                hacerFoto();
                enviarMail(true);
                dialog.cancel();
            }
        });
        builder.setNegativeButton("No", new OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                enviarMail(false);
                dialog.cancel();
            }
        }); 
        return builder.create();    
    }

Here is the method where I create the email

private void enviarMail(boolean foto) {
        if(locMail!=null) {
            Intent i = new Intent(Intent.ACTION_SEND);  
            i.setType("message/rfc822");
            i.putExtra(Intent.EXTRA_SUBJECT,"Quiero que sepas donde estoy!"); 
            if(foto && fotoPath != null && fotoPath.length()>0) {
                i.putExtra(Intent.EXTRA_STREAM, Uri.parse(fotoPath));
            }
            i.putExtra(Intent.EXTRA_TEXT,"Hola!\n Estoy en la dirección:" +
                    "\n" + localizarDireccion() +
                    "\n\n(lat= " + dfmail.format(locMail.getLatitude()) + ")" +
                    "\n(long=" + dfmail.format(locMail.getLongitude()) + ") " +
                    "\n \n[Enviado desde GeoLocation]" );  
            startActivity(i);
        }else{
            dialogError("No se puede encontrar una localización").show();
        }
    }

And this is the method where I take the photo:

private void hacerFoto() {  
        //El gran quebradero de cabeza aquí fue que no le daba permisos a la aplicación para escribir en la tarjeta. En el manifest se puede comprobar esta directiva
        File carpeta = new File(Environment.getExternalStorageDirectory () + "/GeoLocation/images"); 
        if(!carpeta.exists()){
            carpeta.mkdirs();
        }
        fotoPath = Environment.getExternalStorageDirectory() + "/GeoLocation/images/GLPict"+cogerFecha()+".jpg";
        Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        Uri output = Uri.fromFile(new File(fotoPath));
        intent.putExtra(MediaStore.EXTRA_OUTPUT, output);
        startActivityForResult(intent, 1);
    }

The problem is that the intent of sendMail (enviarMail) doesn’t wait to the first method takePhoto (hacerFoto) has finished. Is there some method that let me say to the sendMail intent to wait until the method takePhoto has finished?

Thanks for all and SORRY FOR MY ENGLISH!!!

  • 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-04T21:37:22+00:00Added an answer on June 4, 2026 at 9:37 pm

    Start first intent like startActivityForResult(intent, requestCode) and when this will return onActivityResult gets called, and from there you can start the second intent.

    edit ::
    do it like this ::

    private Dialog comprobarFoto() {
        AlertDialog.Builder builder = new AlertDialog.Builder(this); 
    
        builder.setMessage("¿Desea adjuntar una foto con este mensaje de su posición actual?");
        builder.setPositiveButton("Si", new OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                hacerFoto();
          ///////////// do not call enviarMail(true) from here, call it from onActivityResult, see below //////////////////
                dialog.cancel();
            }
        });
        builder.setNegativeButton("No", new OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                enviarMail(false);
                dialog.cancel();
            }
        }); 
        return builder.create();    
    }
    
    @Override
    protected void onActivityResult(int reqCode,int resultCode,Intent intent)
    {
        if(resultCode == Activity.RESULT_OK)
        {
            if( reqCode == 1)
                enviarMail(true); //////// call from here ///////   
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some troubles with positioning my label/password field. With this code they both
Right now I have some troubles. I'm finding a way to solve one problem.
I'm trying to start my java game but I have some troubles with the
Ok so I have a simple Android app that I want it to go
Especially android-developers :) I have some troubles with application menu which i try to
I have a problem with my android algorithm. I want some certain thing happends
I have some troubles with yet another Internet Explorer beauty. Scenario : I disable
I'm new to android programming (writing my first app now) and I need some
Hello I am in the process of making an Android app that pulls some
I am currently working on an android app that is causing me some trouble.

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.