Go back to start activity after sending email in android

I want to return to proactive activity after sending email by calling the email client in android. But it does not work at all. I tried the code below.

try { path = android.provider.MediaStore.Images.Media.insertImage( getContentResolver(), returnedBitmap, "diploma.png", null); Uri diplomaUri = Uri.parse(path); //send email with the above generated image as attachment final Intent emailIntent2 = new Intent(android.content.Intent.ACTION_SEND); emailIntent2.putExtra(Intent.EXTRA_SUBJECT, "Potty Diploma for Teddy"); emailIntent2.putExtra(Intent.EXTRA_TEXT, Html.fromHtml("")); emailIntent2.putExtra(Intent.EXTRA_STREAM, diplomaUri); emailIntent2.setType("image/png"); startActivityForResult(Intent.createChooser(emailIntent2, "Email:"), EMAIL_SUCCESS); } catch(Exception e) { final AlertDialog.Builder builder = new AlertDialog.Builder(v.getContext()); builder.setTitle("Device Media Access"); builder.setMessage("Failed to access media store of the device"); builder.setCancelable(false); builder.setPositiveButton("OK", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { dialog.cancel(); } }); AlertDialog alert = builder.create(); alert.show(); } @Override public void onActivityResult(int reqCode, int resultCode, Intent data){ super.onActivityResult(reqCode, resultCode, data); switch(reqCode){ case (EMAIL_SUCCESS): if (resultCode == RESULT_OK){ Intent myIntent = new Intent(Progress.this, iGoPotty.class); myIntent.putExtra("tab_id", 2); startActivity(myIntent); } } } 
+4
source share
2 answers

It seems that you are trying to create a new intention to return to your original activity? why not just setResult() and finish() in onActivityResult() ? I cannot understand what you are trying to do without any code or a bit of additional information on your part. I assume that you are calling setResult() and finish() correctly in your email. Does it mean to be caught here in onActivityResult() ? First, you set a breakpoint and went over to find out if you get any result? If so, what shoots and what doesn't? If you shoot, this is your myIntent != null , maybe there is a coverage problem?

0
source

Try adding a flag (see below) to get the result from the mail client:

intent.addFlags (Intent.FLAG_ACTIVITY_FORWARD_RESULT);

Thus, you will return to your activities.

0
source

All Articles