Wyświetl okno potwierdzenia przed wysłaniem wiadomości SMS

Jestem nowością w Androidzie i całkowicie związałem moją aplikację, ale chcę teraz ją zmienić.

Gdy ktoś wysyła sms, chcę wyświetlić okno dialogowe potwierdzenia wysyłania smsów z prośbą o wysłanie lub nie. I muszę stworzyć wspólną klasę, dla której napisałem kod źródłowy i działa dobrze, ale jeśli użytkownik nie kliknie Tak lub Anuluj, okno dialogowe gaśnie, ale chciałbym, aby nadal wyświetlało się, dopóki użytkownik nie kliknie Tak lub Przycisk Anuluj.

Jak można to rozwiązać?

<code>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;       
    }
}*/
}
</code>

questionAnswers(2)

yourAnswerToTheQuestion