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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T10:23:04+00:00 2026-05-30T10:23:04+00:00

Ok, so i am making a Android app that is able to send sms

  • 0

Ok, so i am making a Android app that is able to send sms msgs multiple times with intervals between the amount of messages is sent. This is partially working but it sometimes does not. For example when i input 20 msgs to send it sends 16 or maybe a little more. Also when i push the button it freezes until it finishes sending the SMS’s.is there anyway that someone could tell me what is wrong with my code? i have tried a few fixs that are not working very well and thought i would come here for help after many failed trys at this. PS there is more code then this but this is where the issue resides i beleive. Thanks for reading
EDIT: FIXED!

  • 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-30T10:23:06+00:00Added an answer on May 30, 2026 at 10:23 am

    The button is “freezing” because the UI thread is sending all 20 SMS before it frees up to do other things.

    I would look into AsyncTask. This is Android’s way to easily thread. Essentially what you would do it spawn a new thread in the background with AsyncTask. This frees up the UI thread so that it looks like everything is normal to the user (no freezing), while the AsyncTask is doing all of the work in the background with doInBackground. Then when the Task is done use onPostExecute to notify the UI that it is done and perhaps tell the user something. You’d put the call to MyAsyncTask.execute(smsDataHere) in the onClick.

    That link to AsyncTask is fairly comprehensive for simple purposes and has example code.

    I’m not sure exactly why it only send 16 or so messages, but I can see right off the bat that you are missing some curly braces and that they don’t quite match up the way you want them to. I would look there first. Also, is there a reason for the second for loop? size is always 1, so it is just sending each message twice.

    EDIT:
    Here is some sample code. I’m not going to promise it works in your exact app, but it will show you how the AsyncTask works and give you a starting point. I also tried to fix any problems with the curly braces and did a little cleaning up. I still recommend looking over the documentation to make sure you understand how it works. I hope this helps you.

    public void onClick(View v){                
        String phoneNo = putpn.getText().toString();
        String message = txtMessage.getText().toString();
        String txts = txtAmount.getText().toString();
        String inter = interval.getText().toString();
    
        if (msgCount > 21){
            Toast.makeText(getBaseContext(), "That is too many txts, the max is 20", Toast.LENGTH_SHORT).show();
        }
        else{
            MySmsTask.execute(phoneNo, message, txts, inter);
        }
    }
    
    private class MySmsTask extends AsyncTask<String, Void, Integer> {
        @Override
        protected Integer doInBackground(String... messageData) {
            int sentCount = 0;
            int size = 1;
            int delay = Integer.parseInt(messageData[3]);
            int msgCount = Integer.parseInt(messageData[2]);
    
            if (phoneNo.length()>0 && message.length()>0){
                for (sentCount = 0; sentCount < msgCount; sentCount++) {
                    for (int i = 0; i < size; i++) {
                        sendSMS(messageData[0], messageData[1]);
                        Thread.sleep(delay * 1000);
                    }
                }
            }
            return sentCount;
        }
    
        @Override
        protected void onPostExecute(Integer result) {
            Toast.makeText(getBaseContext(), "Sent " + sentCount + " messages", Toast.LENGTH_SHORT).show();
        }
    }
    
    private void sendSMS(String phoneNumber, String message){        
        PendingIntent pi = PendingIntent.getActivity(this, 0,
                new Intent(this, Object.class), 0);
        SmsManager sms = SmsManager.getDefault();
        sms.sendTextMessage(phoneNumber, null, message, null, null);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm making an Android app that tracks a user and displays their location in
I am making an android app that shows the Calendar day view, it looks
Ive made edits since the orignal post Im making an android app that connects
Okay, so i am making an android app that has tabs, now my problem
I hope I can explain this properly. I'm making an android app that, when
I'm making a function in my android app that, at a home screen the
So I'm making an Android 2.2 app that uses GLSurfaceView. My question is, since
I'm making an android 1.6 app that uses phone's camera. In order to do
I'm working on making an iPhone version of an Android app that I've written
I am making an android app which will have two services that will keep

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.