3

I have a sms sender with pendingIntent and once the sms sent it opens a dialog. Here's the code from SMS sender

public final void sendSmsByManager(final String code) 
{
        progressDialog = new ProgressDialog(Registration.this);
        progressDialog.setTitle("Please wait");
        progressDialog.setMessage("Sending SMS Verification Code...");
        progressDialog.setCancelable(false);
        progressDialog.setCanceledOnTouchOutside(false);
        progressDialog.show();

    String sent = "SMS_SENT";

    PendingIntent sentPI = PendingIntent.getBroadcast(Registration.this,

    2, new Intent(sent), 0);

    Registration.this.registerReceiver(new BroadcastReceiver() {
        @Override
        public void onReceive(Context arg0, Intent arg1) {

            switch (getResultCode())

            {

            case Activity.RESULT_OK:

                // Toast.makeText(getBaseContext(), "SMS sent",

                // Toast.LENGTH_SHORT).show();
                progressDialog.dismiss();
                dialog_confirm(code,Registration.this);
                // saveRegistration();

                break;

            case SmsManager.RESULT_ERROR_GENERIC_FAILURE:
                progressDialog.dismiss();

                Toast.makeText(getApplicationContext(), "Generic failure",

                Toast.LENGTH_SHORT).show();

                // Toast.makeText(getApplicationContext(), "code" + code,

                // Toast.LENGTH_SHORT).show();

                status = "Generic failure";

                break;

            case SmsManager.RESULT_ERROR_NO_SERVICE:
                progressDialog.dismiss();
                Toast.makeText(
                        myContext,
                        "No service. Check mobile network connection." + ""
                                + "",

                        Toast.LENGTH_SHORT).show();

                status = "No service";

                break;

            case SmsManager.RESULT_ERROR_NULL_PDU:
                progressDialog.dismiss();
                Toast.makeText(getApplicationContext(), "Null PDU",

                Toast.LENGTH_SHORT).show();

                status = "Null PDU";

                break;

            case SmsManager.RESULT_ERROR_RADIO_OFF:
                progressDialog.dismiss();
                Toast.makeText(getApplicationContext(), "Radio off",

                Toast.LENGTH_SHORT).show();

                status = "Radio off";

                break;

            }

        }

    }, new IntentFilter(sent));

    SmsManager sms = SmsManager.getDefault();

    sms.sendTextMessage(txt_mobileno.getText().toString(), null, code,
            sentPI, null);

}

And I call the dialog from the Activity.RESULT_OK

 public void dialog_confirm(final String SMSCode,Context context) 
 {

     dialog = new Dialog(context);


    dialog.getWindow().requestFeature(Window.FEATURE_NO_TITLE);
    dialog.getWindow().setBackgroundDrawable(
            new ColorDrawable(android.graphics.Color.TRANSPARENT));
    dialog.setContentView(R.layout.dialog_confirm);

    final EditText txt_code = (EditText) dialog.findViewById(R.id.txt_code);
    Button btn_add = (Button) dialog.findViewById(R.id.btn_confirm);
    Button btn_cancel = (Button) dialog.findViewById(R.id.btn_cancel);

    btn_add.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            String code = txt_code.getText().toString();

            if (code.equals(SMSCode)) {
                match = true;
                // save
                if (Constants.ID != 0) {

                    updateRegistration();

                } else {

                    saveRegistration();

                }

                dialog.dismiss();

            } else {
                DialogUtil.createErrorDialog(Registration.this, "Registration Error",
                        "SMS verification code does not match!").show();

            }

        }

    });

    btn_cancel.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            dialog.dismiss();
        }
    });

    dialog.setCancelable(false);
    dialog.show();
}

and error point on dialog.show Here's the Screenshot. enter image description here

CodeMonkey
  • 11,196
  • 30
  • 112
  • 203
user3463171
  • 81
  • 2
  • 6
  • Do you have any updates on that issue? I am facing a similar situation with exactly the same error.. – JcDenton86 Sep 23 '15 at 10:22
  • actually check [this](http://stackoverflow.com/questions/7811993/error-binderproxy45d459c0-is-not-valid-is-your-activity-running) SO question – JcDenton86 Sep 23 '15 at 14:01

2 Answers2

1

The problem is probably that the context was destroyed by the time the dialog was supposed to be shown. This can be avoided like this:

if(!((Activity) context).isFinishing())
{
    //show dialog
}
CodeMonkey
  • 11,196
  • 30
  • 112
  • 203
0

If you have added the following line in your AndroidManifest.xml when defining the activity

android:noHistory="true"

Your defined activity in the AndroidManifest.xml file should look like this

<activity
    android:name=".Signup"
    android:label="@string/title_activity_signup"
    android:parentActivityName=".LoginSignup"
    android:screenOrientation="portrait"
    android:theme="@style/AppTheme.NoActionBar">
    <meta-data
        android:name="android.support.PARENT_ACTIVITY"
        android:value="com.yourpackage.LoginSignup" />
Chic
  • 9,836
  • 4
  • 33
  • 62
Naveen Kumar
  • 31
  • 10