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 6794815
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T18:16:03+00:00 2026-05-26T18:16:03+00:00

My TextMessage activity is passed a name and phone number, and then proceeds to

  • 0

My TextMessage activity is passed a name and phone number, and then proceeds to allow the user to type a text message, and send the message on.

My activity does what it is supposed to, however, after sending the message it calls my TextMessage activity again but it doesn’t retain the name and phone number.

Is there a way I can do that? I know I can’t use “putExtra” for a pendingIntent, so I’m at a loss as to how to do this.

Also, my cancel button crashes in this circumstance because the name and phone number that I received from the previous Intent are now null.

My code:

public class TextMessage extends Activity {

    private Button cancel;
    private EditText message;
    private TextView nameInfo;
    private Button send;

    private String searchName;
    private String searchPhone;

    private SmsManager smsManager;

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.message);

        cancel = (Button) findViewById(R.id.cancelmessage);
        send = (Button) findViewById(R.id.sendmessage);
        message = (EditText) findViewById(R.id.messagebodytext);
        nameInfo = (TextView) findViewById(R.id.messageuser);

        searchName = getIntent().getStringExtra("name");
        searchPhone = getIntent().getStringExtra("phonenumber");    

        nameInfo.setText(searchName + ": " + searchPhone);

        smsManager = SmsManager.getDefault();
        //final PendingIntent sentIntent = PendingIntent.getActivity(this, 0, new Intent(this, TextMessage.class), 0);
        Intent intent = new Intent(this, TextMessage.class);
        intent.putExtra("name", searchName);
        intent.putExtra("phonenumber", searchPhone);
        final PendingIntent sentIntent = PendingIntent.getActivity(this, 0, intent, 0);

        send.setOnClickListener(new Button.OnClickListener() {
            public void onClick(View v) {
                String messageBody = message.getText().toString();
                if (messageBody.length() > 0) {
                    smsManager.sendTextMessage(searchPhone, null, messageBody, sentIntent, null);
                    finish();
                }
            }
        });

        cancel.setOnClickListener(new Button.OnClickListener() {
            public void onClick(View v) {
                Intent intent = new Intent(TextMessage.this, SMS.class);
                intent.putExtra("name", searchName);
                startActivity(intent);
                finish();
            }
        });
    }
}
  • 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-05-26T18:16:03+00:00Added an answer on May 26, 2026 at 6:16 pm

    Instead of using this in the constructor of the pending intent. You should created it outside and added your extras to that intent. I don’t think it matters for this case as much but if you had another pending intent with the same information you would need the update current to override the extras.

     intent = new Intent(this, TextMessage.class);
     intent.putExtra("","");
     final PendingIntent sentIntent = PendingIntent.getActivity(this, 0, intent, 0);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my application, I need to send the text message to the user after
I am trying to search the AddressBook for Phone Numbers by name, -(void)textMessage{ ABAddressBookRef
Trying to send a text message more than 100 times, is there any way
I am attempting to create a simple app that can send a text message
The Oracle Docs say - A TextMessage object is used to send a message
My app deals with phone calls.I want to send an auto textmessage(sms) to the
I'm setting up my site to receive info from people via text message. The
Consider the following code : class TextMessage{ public : TextMessage(){}; TextMessage(std::string _text):text(_text){} std::string text;
Which one is better in performance for sending object message? Create ObjectMessage and send
I have a translucent AlertDialog set to show if the user receives a text

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.