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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T03:01:22+00:00 2026-06-08T03:01:22+00:00

I am planning on sending SMS messages in my app. I have this code

  • 0

I am planning on sending SMS messages in my app. I have this code so far:

private void sendMessage(String number, String message ){

        dlg.setCancelable(false);
        dlg.setMessage("Sending...");


        InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
        imm.hideSoftInputFromWindow(etText.getWindowToken(), 0);

        etText.setText("");

        dlg.show();

        SmsManager sms = SmsManager.getDefault();

        Intent sendingIntent = new Intent(Intent.ACTION_SEND);
        sendingIntent.putExtra("number", number);
        sendingIntent.putExtra("message", message);
        PendingIntent sendPI = PendingIntent.getBroadcast(this, 0, sendingIntent, PendingIntent.FLAG_ONE_SHOT);

        sms.sendTextMessage(number, null, message, sendPI, null);

    }

My Receiver:

public class SMSSenderReceiver extends BroadcastReceiver {


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

        int resultCode = this.getResultCode();

         String number = intent.getExtras().getString("number");
         String message = intent.getExtras().getString("message");

         ContentValues val = new ContentValues();
         val.put("address", number);
         val.put("body", message);

         switch(resultCode){

         case Activity.RESULT_OK:

                context.getContentResolver().insert(Uri.parse("content://sms/sent"), val);

                if (MessageListActivity.dlg != null){
                    if (MessageListActivity.dlg.isShowing()){
                        MessageListActivity.dlg.dismiss();
                    }
                }

         }
    }

}

In my methods for my activity:

SMSSenderReceiver receiver = new SMSSenderReceiver();

@Override
public void onCreate(Bundle b){

    this.registerReceiver(receiver,  new IntentFilter(Intent.ACTION_SEND));
}

@Override
public void onResume(){ 
  super.onResume();
   this.registerReceiver(receiver);

}

@Override
public void onStop(){
super.onStop();
this.unRegisterReceiver(receiver);
}

@Override
public void onPause(){
super.onPause();
this.unRegisterReceiver(receiver);
}

Now the problem is that when I send a message with my phone screen on, it does fine by dismissing the dialog and putting the message into the sent box when it is sent, but when I try to send a message and immediately turn off my screen it sends the message, but doesn’t dismiss the dialog nor put the message into the sent folder. I know this has something to do with life cycles of the activity, but I’m not sure what to do with the onPause and onResume functions. If I don’t unregister the receiver when the phone turns off then I get an error that the receiver has already been leaked error. Is there anyone that knows of a way of receiving the broadcast when my phone is off? Or of a way for getting the ACTION_SEND broadcast through the manifest?

  • 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-08T03:01:23+00:00Added an answer on June 8, 2026 at 3:01 am

    Turning off screen will always call onStop(), but not with onDestroy(). onDestroy() could be called in case the system is losing memory… I think you can unregister the receiver in onDestroy()…

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

Sidebar

Related Questions

I am planning to build an application where I'll be sending SMS to people
So, after spending the last week carefully designing and planning out my app, a
im planning to create a movie file that might have over 16,000 frames?i know
Iam planning to create an app, and not to publish it at the google
I have a field device which keeps on sending data over to any designated
I am trying to write a server side code for sending push notifications for
I have to work on CRON which will be sending email to subscriber weekly
I have an already running basicHttpBinding with transferMode=Buffered WCF service for sending small amount
I am working on a project that involves sending some very small encrypted messages
I'm planning on developing an app for android that requires a back-end server to

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.