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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T00:44:34+00:00 2026-06-04T00:44:34+00:00

I am new to Android and I have bound my application completely but I

  • 0

I am new to Android and I have bound my application completely but I wish to a change now in it.

When someone sends an sms, I want to display a confirmation dialog for sending sms asking for send or not. And I have to make a common class for that I have written the source code and it works fine but if user does not click on Yes or Cancel the dialog goes out but I wish that it will still display until user does not click on Yes or Cancel button.

How it can be solved?

public void send_SMS( final String message)
    { 
    try{


        AlertDialog.Builder dialog = new AlertDialog.Builder(ctx);
        dialog.setTitle("Send SMS");
        dialog.setMessage("Are U sure want to Send SMS");
        dialog.setCancelable(true);
        dialog.setPositiveButton("Yes", new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                // TODO Auto-generated method stub
                sentpi = PendingIntent.getBroadcast(ctx, 0, new Intent(SENT),0);
                delpi = PendingIntent.getBroadcast(ctx, 0, new Intent(DELIVERED), 0);//
                String id = message.substring(3, 4);
                int msgId = Integer.valueOf(id, 16).intValue();

                if(dba.IsConOpenOrClose()==false)
                    dba.Open();
                if(ConstantClass.SelectCord.equals("All")){
                    if(msgId == 3 || msgId == 9){   
                    devId = message.substring(4, 20);
                    ConstantClass.CurrentId = devId;
                    strSql = new String("SELECT * FROM "+ ConstantClass.dbName[2] + " WHERE " + DataBaseAdapter.Key_DevID + " = ?");
                    cur = dba.ExecuteSelect(strSql, devId);
                    if(cur!=null)
                        cur.moveToFirst();
                    int cordId = cur.getInt(cur.getColumnIndex(DataBaseAdapter.Key_DevCoordId));
                    phoneNumber = dba.getSendSmsMobileNo(cordId);
                    dba.prcUpdateOrClean(devId, 1);
                    cur.close();
                    }
                }else{
                    phoneNumber = dba.getSendSmsMobileNo(dba.CurrentWorkingCoordinator(DataBaseAdapter.Key_SendCoord, 1));
                /*********now getting the Field smsProcess Update for particular devices ********************/
                if(msgId == 3 || msgId == 9 || msgId == 7){
                    devId = message.substring(4, 20);
                    if(dba.IsConOpenOrClose()==false)
                        dba.Open();
                    ConstantClass.CurrentId = devId;
                    dba.prcUpdateOrClean(devId, 1);

                }else if(msgId == 15 || msgId == 13 || msgId == 11 || msgId == 1){
                    if (dba.IsConOpenOrClose()==false)
                        dba.Open();
                    phoneNumber = dba.getSendSmsMobileNo(dba.CurrentWorkingCoordinator(DataBaseAdapter.Key_SendCoord, 1));
                    if(phoneNumber.length()==11){
                        pdNo = phoneNumber.substring(1, 11);
                    }else{
                        pdNo = phoneNumber.substring(0, 10);
                    }
                    devId = "000000" + pdNo;
                    ConstantClass.CurrentId = devId;                
                    dba.prcUpdateOrClean(devId, 1);

                }
                }
                  SmsManager sms = SmsManager.getDefault();
                  if(phoneNumber!=null){
                      sms.sendTextMessage(phoneNumber, null, message.toUpperCase(), sentpi, delpi); 
                  }else{
                      throw new java.lang.NullPointerException() ;
                  }               
            }
        });
        dialog.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                // TODO Auto-generated method stub
                dialog.cancel();
            }
        });
        AlertDialog dlg = dialog.create();
        dlg.show();       
    }catch(Throwable e){
        dlg = new ExceptionDialog(this.ctx,"Sending SMS",e.getMessage());
        dlg.show();
    }   
}
public BroadcastReceiver sms_send = new BroadcastReceiver(){
    @Override
    public void onReceive(Context context,Intent intent){
        String Info = "Send Info:";
        switch(getResultCode()){
        case Activity.RESULT_OK:
            Info += "Sms Send Successfull";
            break;
        case SmsManager.RESULT_ERROR_GENERIC_FAILURE:
            Info += "Sms Sending faild : genric faliure";
            break;
        case SmsManager.RESULT_ERROR_NO_SERVICE:
            Info += "Sending failed due to no Service";
            break;
        case SmsManager.RESULT_ERROR_NULL_PDU:
            Info += "Send failed : Null PDU";
            break;
        case SmsManager.RESULT_ERROR_RADIO_OFF:
            Info += "Send failed: Radio Service OFF";
            break;
        }
         Toast.makeText(ctx, Info, Toast.LENGTH_SHORT).show();
    }
};
public BroadcastReceiver sms_delivered = new BroadcastReceiver(){
    @Override 
    public void onReceive(Context context, Intent intent){
        String Info = "SMS Delivered :";
        switch(getResultCode()){
        case Activity.RESULT_OK:
            Info += "Sms Deliverd";
            break;
        case Activity.RESULT_CANCELED:
            Info += "Sms not Delivered";
            break;
        }
        Toast.makeText(ctx, Info, Toast.LENGTH_SHORT).show();
    }
};
public IntentFilter getSentIntentFilter(){
    return new IntentFilter(SENT);      
}
public IntentFilter getDeliveredFilter(){
    return new IntentFilter(DELIVERED);
}
/*private void reThrow(MyException ex){
    if(ex.nullPointerException instanceof NullPointerException  ){

    }
}
private class MyException extends Exception{
    public Exception nullPointerException;
    public MyException (){}
    public MyException(Exception NullPointerException){
        this.nullPointerException = NullPointerException;       
    }
}*/
}
  • 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-04T00:44:36+00:00Added an answer on June 4, 2026 at 12:44 am
    dialog.setCancelable(true); should be like  dialog.setCancelable(false);
    

    It prevents closure of alert dialog when user presses back button 🙂

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

Sidebar

Related Questions

I am new in Android. I have develop an app. And now want to
I am a bit new with android but I have some java experience. So
i am creating a new android application.i am using the table layout. I have
Ok, im fairly new to android but i have managed to teach myself the
I am new to Android. I have tried an sample application for status bar
still pretty new to android I have to clone an iphone application. Im having
i'm a new android developer. I have an application installed in phone. This application
I'm fairly new to Android programming and to Java in general, but I have
Firstly, Im new to android but have years of various other programming experience on
I am a relatively new Android developer but have gotten pretty familiar with the

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.