problem with sending email ... goes back to previous activity
I have 2 activities- A and B. I have a list on activity A and if I click on it, it goes to activity B开发者_如何学运维. On activity B, I have a button for sharing email with the following code :
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);
}
});
Now, when I send an email, the email window closes and activity B also closes. I am not sure why that is happening. Any hints ? Thanks.
logcat output:
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
you have to use intent.crateChoose in start activity. now use the edited code.
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..."));
}
});
精彩评论