Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8326609
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T00:49:04+00:00 2026-06-09T00:49:04+00:00

I’ve got a TabHost application where the user can send an email from any

  • 0

I’ve got a TabHost application where the user can send an email from any of the tab activities. I want to write one class which can be instantiated from any of the activities which will handle launching the Email intent but not sure this is the ideal way to do it.

Although It saves some code duplication, it seems like a lot of overhead having to create an intent which creates another intent to launch createChooser(). Is there a better way?

Application code

Intent send = new Intent (this, Email.class); 
send.putExtra ("mailto", EMAIL_ADDRESS); 
send.putExtra ("subject", SUBJECT); 
send.putExtra ("body", MSG_BODY); 
this.startActivity (send);

Email class

public class Email extends Activity
{
    @Override
    protected void onCreate (Bundle savedInstanceState)
    {
        super.onCreate (savedInstanceState);
        Log.d ("email" , " oncreate");

        Bundle ex = getIntent ().getExtras ();
        String mailto =  ex.getString ("mailto");
        String subject = ex.getString ("subject");
        String body = ex.getString ("body");

        if (body == null)
           body = "";
        if (subject == null)
           subject = "";

        try
        { 
            // use the builtin chooser for users mail app or SMS
            /* NOTE: AndroidManifest has android:noHistory="true" for this */
            Intent sendIntent = new Intent(android.content.Intent.ACTION_SEND);
            sendIntent.setType("text/plain");
            sendIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String [] {mailto});
            sendIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject);
            sendIntent.putExtra(android.content.Intent.EXTRA_TEXT, body);
            startActivityForResult (Intent.createChooser(sendIntent, "Send via which Application?"), 0);
        }
        catch (Exception e) 
        {
            Toast.makeText (this, "No activity was found to handle this action",Toast.LENGTH_SHORT).show();
        }
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T00:49:06+00:00Added an answer on June 9, 2026 at 12:49 am

    Ok, so as it turns out, this was rather trivial. The sticky part was passing the Context and launching the intent from it. Hope it helps someone else.

    package foo.test.email;
    
    import android.app.Activity;
    import android.content.Context;
    import android.content.Intent;
    import android.widget.Toast;
    
        public class Email
        {
    
            public static void send (Context ctx, String addy, String subject, String body)
            {
                try
                {
                    // use the builtin chooser for users 'send' app
                    Intent sendIntent = new Intent(Intent.ACTION_SEND);
                    sendIntent.setType("text/plain");
    
                    sendIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String [] {addy});
                    sendIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject);
                    sendIntent.putExtra(android.content.Intent.EXTRA_TEXT, body);
    
                    ctx.startActivity (Intent.createChooser(sendIntent, "Send via which Application?"));
                }
                catch (Exception e) 
                {
                    Toast.makeText (ctx, "No activity was found to handle this action",Toast.LENGTH_SHORT).show();
                }
            }
    
        }
    

    and to call the static send method from another class:

    Email.send (mainApp.this, "who@where", "a subject", "a body");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Does anyone know how can I replace this 2 symbol below from the string
I want to count how many characters a certain string has in PHP, but
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a jquery bug and I've been looking for hours now, I can't
I've got a string that has curly quotes in it. I'd like to replace
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I have a French site that I want to parse, but am running into
I want use html5's new tag to play a wav file (currently only supported

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.