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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T15:25:55+00:00 2026-05-30T15:25:55+00:00

I have a problem(again)…now i want to pass a String from one Activity to

  • 0

I have a problem(again)…now i want to pass a String from one Activity to another.

The first Activity is SMSReceiver, i make a ListView for contact’s number and message’s here.

This is the complete code :

public class SMSReceiver extends BroadcastReceiver {

private static final int NOTIF_ID = 0;

@Override
public void onReceive(Context arg0, Intent arg1) {
    // TODO Auto-generated method stub

    Bundle bundle = arg1.getExtras();
    SmsMessage[] msgs = null;
    String str = "";
    if (bundle != null) {
        Object[] pdus = (Object[]) bundle.get("pdus");
        msgs = new SmsMessage[pdus.length];

        for (int i = 0; i < msgs.length; i++) {
            msgs[i] = SmsMessage.createFromPdu((byte[]) pdus[i]);
            str += "You Get New SMS from " + msgs[i].getOriginatingAddress();
            str += " :";                    str += msgs[i].getMessageBody().toString();
            str += "\n";

        Toast.makeText(arg0, str, Toast.LENGTH_SHORT).show();

        NotificationManager nm = (NotificationManager) arg0.getSystemService(Context.NOTIFICATION_SERVICE);

        String tickerText = str;

        Notification notif = new Notification(R.drawable.ic_launcher, tickerText, System.currentTimeMillis());

        notif.flags = Notification.FLAG_AUTO_CANCEL;

        String contentTitle = msgs[i].getOriginatingAddress();
        String contentText = msgs[i].getMessageBody().toString();

        Intent intent = new Intent(arg0, SMSReply.class);
        PendingIntent pi = PendingIntent.getActivity(arg0, 0, intent, 0);

        notif.setLatestEventInfo(arg0, contentTitle, contentText, pi);
        notif.defaults = Notification.DEFAULT_ALL;
        nm.notify(NOTIF_ID, notif);

        String tempSMS = msgs[i].getOriginatingAddress();
        Intent pass = new Intent();
        Bundle bundlePass = new Bundle();

        bundlePass.putString("key", tempSMS);
        pass.putExtras(bundlePass);
        }
    }
}

And this is the PART OF SMSReceiver that i used for passing a String via Bundle and Intent

String tempSMS = msgs[i].getOriginatingAddress();
        Intent pass = new Intent();
        Bundle bundlePass = new Bundle();

        bundlePass.putString("key", tempSMS);
        pass.putExtras(bundlePass);

Now, this is the complete SMSReply Class, the class that i want to get a phone number(String) from SMSReceiver Class(so user don’t have to type it again)

public class SMSReply extends Activity implements OnClickListener {

EditText etPhone, etMessage;
Button bSend;
String phone, message;

@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.reply);

    etPhone = (EditText) findViewById(R.id.etPhone);
    etMessage = (EditText) findViewById(R.id.etMessage);
    bSend = (Button) findViewById(R.id.bSend);
    bSend.setOnClickListener(this);
}

public void onClick(View arg0) {
    // TODO Auto-generated method stub
    Intent get = new Intent();

    Bundle bundleGet = get.getExtras();
    phone = bundleGet.getString("answer");
    etPhone.setText(phone);

    phone = etPhone.getText().toString();
    message = etMessage.getText().toString();

    if (phone.length() > 0 && message.length() > 0) {
        sendSms(phone, message);
    } else {
        Toast.makeText(getBaseContext(),
                "Please enter both phone number and message",
                Toast.LENGTH_SHORT).show();
    }
}

private void sendSms(String phone2, String message2) {
    // TODO Auto-generated method stub
    String SENT = "SMS_SENT";
    String DELIVERED = "SMS_DELIVERED";

    PendingIntent sentPI = PendingIntent.getBroadcast(this, 0, new Intent(
            SENT), 0);
    PendingIntent deliveredPI = PendingIntent.getBroadcast(this, 0,
            new Intent(DELIVERED), 0);

    registerReceiver(new BroadcastReceiver() {

        @Override
        public void onReceive(Context arg0, Intent arg1) {
            // TODO Auto-generated method stub
            switch (getResultCode()) {
            case Activity.RESULT_OK:
                Toast.makeText(getBaseContext(), "SMS sent",
                        Toast.LENGTH_SHORT).show();
                break;
            case SmsManager.RESULT_ERROR_GENERIC_FAILURE:
                Toast.makeText(getBaseContext(), "Generic Failure",
                        Toast.LENGTH_SHORT).show();
                break;
            case SmsManager.RESULT_ERROR_NO_SERVICE:
                Toast.makeText(getBaseContext(), "No Service",
                        Toast.LENGTH_SHORT).show();
                break;
            case SmsManager.RESULT_ERROR_NULL_PDU:
                Toast.makeText(getBaseContext(), "Null PDU",
                        Toast.LENGTH_SHORT).show();
                break;
            case SmsManager.RESULT_ERROR_RADIO_OFF:
                Toast.makeText(getBaseContext(), "Radio Off",
                        Toast.LENGTH_SHORT).show();
                break;
            }
        }
    }, new IntentFilter(SENT));

    registerReceiver(new BroadcastReceiver() {

        @Override
        public void onReceive(Context context, Intent intent) {
            // TODO Auto-generated method stub
            switch (getResultCode()) {
            case Activity.RESULT_OK:
                Toast.makeText(getBaseContext(), "SMS Delivered",
                        Toast.LENGTH_SHORT).show();
                break;
            case Activity.RESULT_CANCELED:
                Toast.makeText(getBaseContext(), "SMS not Delivered",
                        Toast.LENGTH_SHORT).show();
            }
        }
    }, new IntentFilter(DELIVERED));
    SmsManager sms = SmsManager.getDefault();
    sms.sendTextMessage(phone, null, message, sentPI, deliveredPI);
}

And this is the PART OF SMSReply class, where i put some code’s for taking a String from SMSReceiver and set that String in my EditText 😀

Intent get = new Intent();

    Bundle bundleGet = get.getExtras();
    phone = bundleGet.getString("answer");
    etPhone.setText(phone);

    phone = etPhone.getText().toString();
    message = etMessage.getText().toString();

Thats All!
Please help me, and thank you very much! 😀

PS : Sory for the long post, and sory if my English is not good, English is not my native languange 😀

  • 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-30T15:25:56+00:00Added an answer on May 30, 2026 at 3:25 pm

    While setting the extra arguments in bundle, you put that bundle in pass Intent and you are doing nothing of that pass Intent. Actually, you should pass these bundle into the intent which you are passing for Notification, i.e. in intent Intent.
    intent.putExtras(bundlePass);.

    Similarly, while reading the argument from bundle, you are accessing it from a new intent which is not the actual one which comes, So use Bundle bundleGet = getIntent().getExtras();

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a problem with stopping a service and starting it again and want
I have run into this problem again and now really need to know how
Greetings again, I have this problem again on C but now using struct. Having
again have problem with opends now i would like to save unicode in the
i have againg a problem with completition. now i can't get any suggestion. Sure
I have problem with return statment >.< I want to store all magazine names
I have problem with ActionLink. I'd like to pass to my ActionLink parameter for
I have problem creating new instance of excel 2007 using VBA (from Access 2002).
I have problem with fancybox. I want to write a function that will run
I again have problem with routing :) When I run application if user is

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.