发送电子邮件的问题...回到以前的活动

时间:2011-09-20 03:43:58

标签: android email

我有2个活动 - A和B.我有一个关于活动A的列表,如果我点击它,它会进入活动B.在活动B上,我有一个按钮,用于使用以下代码共享电子邮件:

shareEmail = (Button) findViewById(R.id.emailButton);

    shareEmail.setOnClickListener(new View.OnClickListener() 
    {
        public void onClick(View v)
        {
            System.out.println("!!! email !!!");


         Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
             emailIntent.setType("text/html");


         emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "sharing something interesting" );
         emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, "sharing something interesting !!" );

         //hideKeyboard();

         activityB.this.startActivity(emailIntent);


        }
    });

现在,当我发送电子邮件时,电子邮件窗口关闭,活动B也关闭。我不确定为什么会这样。任何提示?感谢。

logcat输出:

09-20 04:14:05.969: INFO/ActivityManager(60): Starting activity: Intent { act=android.intent.action.CHOOSER cmp=android/com.android.internal.app.ChooserActivity (has extras) }
09-20 04:14:06.279: INFO/ActivityManager(60): Starting activity: Intent { act=android.intent.action.SEND typ=application/octet-stream flg=0x3000000 cmp=com.android.email/.activity.MessageCompose (has extras) }
09-20 04:14:06.699: DEBUG/dalvikvm(2790): GC_FOR_MALLOC freed 7815 objects / 586592 bytes in 128ms
09-20 04:14:12.099: INFO/ActivityManager(60): Displayed activity com.android.email/.activity.MessageCompose: 5794 ms (total 6097 ms)
09-20 04:14:18.158: DEBUG/dalvikvm(2768): GC_EXPLICIT freed 4016 objects / 308824 bytes in 217ms
09-20 04:14:19.098: WARN/InputManagerService(60): Starting input on non-focused client com.android.internal.view.IInputMethodClient$Stub$Proxy@44e7e000 (uid=10025 pid=2790)
09-20 04:14:19.128: WARN/IInputConnectionWrapper(2790): showStatusIcon on inactive InputConnection
09-20 04:14:19.709: DEBUG/webviewglue(2790): nativeDestroy view: 0x374c08
09-20 04:14:21.339: DEBUG/dalvikvm(60): GC_EXPLICIT freed 10068 objects / 491696 bytes in 207ms
09-20 04:14:24.739: DEBUG/dalvikvm(2696): GC_EXPLICIT freed 1576 objects / 82792 bytes in 123ms
09-20 04:14:29.849: DEBUG/dalvikvm(2790): GC_EXPLICIT freed 5335 objects / 279624 bytes in 224ms

1 个答案:

答案 0 :(得分:0)

你必须在开始活动中使用intent.crateChoose。现在使用编辑过的代码。

shareEmail = (Button) findViewById(R.id.emailButton);

    shareEmail.setOnClickListener(new View.OnClickListener() 
    {
        public void onClick(View v)
        {
            System.out.println("!!! email !!!");


         Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
             emailIntent.setType("text/html");


         emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "sharing something interesting" );
         emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, "sharing something interesting !!" );

         //hideKeyboard();

         activityB.this.startActivity(Intent.createChooser(emailIntent,"Sending Mail..."));


        }
    });