开发者

Return back to initiating activity after sending email in android

开发者 https://www.devze.com 2023-01-28 17:23 出处:网络
I want to return back to the initiating activity after sending email by invoking email client in android. But it is not working at all.

I want to return back to the initiating activity after sending email by invoking email client in android. But it is not working at all. I have tried the below code.

try {
          path = android.provider.Me开发者_如何学PythondiaStore.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);
            }
        }
    }


It seems like you're trying to create a new intent to get back to your initial activity? why not just setResult() and finish() in onActivityResult()? I can't really see what you're trying to do without either some more code or a little more information on your part. I'm assuming you're calling setResult(), and finish(), properly within your email activity. This is then "being" caught here in onActivityResult()? For one, have you set a breakpoint and stepped through to see if you're getting any result whatsoever? If so, what is firing and what isn't? If everything is firing is your myIntent != null, might be scoping issue?


Try to add flag (see below) to get result back from email client:

intent.addFlags(Intent.FLAG_ACTIVITY_FORWARD_RESULT);

This way you will get back to your activity.

0

精彩评论

暂无评论...
验证码 换一张
取 消