Does Android notify that activation activation is complete?

I need to know when the generated activity has ended (through intent), how would I do it?

This is what I have:

    alertDialog.setButton2("Text", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            String uri = "smsto:" + "";
            Intent intent = new Intent(Intent.ACTION_SENDTO, Uri.parse(uri));
            intent.putExtra("sms_body", PASSWORD_GENERATOR
                    .generatePasswordForSeed(seedText, hourToUse));
            intent.putExtra("compose_mode", true);

            // -- open the text message activity
            startActivity(intent);

            // -- I need to reset the calling activity now, but AFTER the text message activity has completed. Right now the SMS closes right away as I have no wait in...
            finish();
            startActivity(getIntent());
        }
    });

EDIT # 1

In the suggestions below, I made some changes. Now, however, the launched SMS activity just “sits there” after sending the text. I can’t figure out how to make him return to defiant activity. This is what I have:

alertDialog.setButton2("Text", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                String uri = "smsto:" + "";
                Intent intent = new Intent(Intent.ACTION_SENDTO, Uri.parse(uri));
                intent.putExtra("sms_body", PASSWORD_GENERATOR
                        .generatePasswordForSeed(seedText, hourToUse));
                intent.putExtra("compose_mode", true);

                startActivityForResult(intent, Activity.RESULT_OK);

                registerReceiver(new BroadcastReceiver() {
                    @Override
                    public void onReceive(Context context, Intent intent) {
                        finish();
                        startActivity(getIntent());
                    }

                }, new IntentFilter("SMS_SENT"));

                ContentResolver contentResolver = getContentResolver();
                Handler handler = new Handler();

                contentResolver.registerContentObserver(Uri
                        .parse("content://sms"), true, new ContentObserver(
                        handler) {

                    @Override
                    public boolean deliverSelfNotifications() {
                        setResult(Activity.RESULT_OK);
                        finish();

                        return super.deliverSelfNotifications();
                    }

                    @Override
                    public void onChange(boolean selfChange) {
                        super.onChange(selfChange);

                        setResult(Activity.RESULT_OK);
                        finish();
                    }
                });
            }
        });

        alertDialog.show();
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        finish();
        startActivity(getIntent());
    }
+5
source share
4 answers

: , - ? , , , , , SMS- . , , .

: startActivityForResult (Intent, int). .

+5

startActivityForResult(intent, positiveinteger);

, , , , , setResult(Activity.RESULT_OK); finish();

, onActivityResult(). , .

Activity.RESULT_OK requestCode, . , onActivityResult() requestCode:

:

      static final int STATIC_RESULT=2; //positive > 0 integer.
      Intent i = new Intent("my.activity.startNewOne");
      i.putExtra("category", category);
    startActivityForResult(i, STATIC_RESULT);

startNewOne , :

    //after the job is done, use the method i mentioned in the comments to check if the sms is delivered/submitted. and proceed if true with this
    if(smsObject.getStatus()==0)//by the docs means successfuly sent
{
    Intent i = getIntent(); //get the intent that has been called, i.e you did called with startActivityForResult();
    i.putExtras(b);//put some data, in a bundle
    setResult(Activity.RESULT_OK, i);  //now you can use Activity.RESULT_OK, its irrelevant whats the resultCode    
    finish(); //finish the startNewOne activity
}

onActivityResult():

@Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {

          if (requestCode == STATIC_RESULT) //check if the request code is the one you've sent
          {
                 if (resultCode == Activity.RESULT_OK) 
                 {
                // this is successful mission, do with it.

                 {
                 } else
                         // the result code is different from the one you've finished with, do something else.
                     }
          }


        super.onActivityResult(requestCode, resultCode, data);

    }
+10

, SmsManager

: SMS- Android | mobiForge

SMS_SENT

: , onCreate()

+2

, exit_on_sent , SMS .

smsIntent.putExtra("exit_on_sent", true);

, , resultCode Activity.RESULT_CANCELLED, , "", , .

+1

All Articles