在android中发送电子邮件后返回启动活动

时间:2010-12-02 09:26:43

标签: android android-activity

我想通过调用android中的电子邮件客户端发送电子邮件后返回启动活动。但它根本不起作用。 我试过以下代码。

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);
            }
        }
    }

2 个答案:

答案 0 :(得分:0)

您似乎正在尝试创建一个新的意图来恢复您的初始活动?为什么不只是setResult()中的finish()onActivityResult()?如果没有更多的代码或更多的信息,我无法真正看到你想要做什么。我假设您在电子邮件活动中正确地呼叫setResult()finish()。然后在onActivityResult()中“抓住”这个?首先,您是否设置了断点并逐步查看您是否获得了任何结果?如果是这样,什么是射击,什么不是?如果一切都是你的myIntent != null,可能是范围问题吗?

答案 1 :(得分:0)

尝试添加标记(见下文)以从电子邮件客户端获取结果:

  

intent.addFlags(Intent.FLAG_ACTIVITY_FORWARD_RESULT);

这样您就可以恢复活动了。