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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T10:38:44+00:00 2026-06-09T10:38:44+00:00

i am developing APP which send sms to Number, if SMS failed the Asynctask

  • 0

i am developing APP which send sms to Number, if SMS failed the Asynctask execute and check after interval to resend sms again but, all my work wasted because i don’t understand the Asynctask here is my Code.

ASYNC Class

        class checkList extends AsyncTask<String, Void, Void> {
        public Void doInBackground(String... p) {
          while (true) {
                already_running_async=true;
              sms.sendTextMessage(phone_nr, null, "SmS Sending", sentPI, null);

              try {
                Thread.sleep(10000);
            } catch (InterruptedException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
              if (isCancelled()) break;

          }
        return null;
        }
        };

SMS sending Code and Error Handling

        bol=false;
    already_running_async=false;
    check=false;

sms = SmsManager.getDefault();
        if(!phone_nr.equals(""))
            sms.sendTextMessage(phone_nr, null,"Sms body" , sentPI, null); 
        sendBroadcastReceiver = new BroadcastReceiver(){
         @Override
            public void onReceive(Context context, Intent intent) {
                switch (getResultCode())
                {
                   case Activity.RESULT_OK:
                       //sms sent if bol true cancel the Asynctask :)
                    if(bol){
                    new checkList().cancel(true);}
                    break;
                    case SmsManager.RESULT_ERROR_GENERIC_FAILURE:
                        if(already_running_async==false){
                        new checkList().execute();
                        bol=true;}
                        break;
                    case SmsManager.RESULT_ERROR_NO_SERVICE:
                        if(already_running_async==false){
                        new checkList().execute();
                        bol=true;}
                        break;
                    case SmsManager.RESULT_ERROR_NULL_PDU:
                        if(already_running_async==false){
                        new checkList().execute();
                        bol=true;}
                        break;
                    case SmsManager.RESULT_ERROR_RADIO_OFF:
                        if(already_running_async==false){
                        new checkList().execute();
                        bol=true;}
                        break;
                }

           }
        };
        registerReceiver(sendBroadcastReceiver , new IntentFilter(SENT));

Problem:
task starts but task remain alive and send sms repeatedly after 10 second i have also put the cancel but asyntask doesnot cancel after successfull sms is sent

Please Help i havent Slept for Night because of this problem 🙁

Regards

  • 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-09T10:38:47+00:00Added an answer on June 9, 2026 at 10:38 am

    This case creates a new asynctask that is immediately canceled.

    case Activity.RESULT_OK:
        //sms sent if bol true cancel the Asynctask :)
        if(bol){
            new checkList().cancel(true);
        }
        break;
    

    To cancel the AsyncTask you need to store it in a variable, like

    checkList smsTask = new checkList();
    smsTask.execute();
    
    // Other app logic
    
    // Replacing the internal portion of that case is the new cancel code
    if (bol) {
        smsTask.cancel(true);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am developing an app which listens to incoming sms. I have added the
i am developing an app which has a evernote integration,everything works perfect but my
I am developing an android app in which i want to send (name,email, cell
I'm currently developing an app which needs to send authentication data with it to
I am developing an app which requires to send email to a person. Everything
Hi am developing a app in which i want to send message automatically to
I'm developing an app through which users can send email messages with attachments. Both
I am developing an app in which the requirement is to send a link
I am developing an api-like app that allows other applications to send requests which
I am developing an app which is supposed to send data to a MySQL

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.