Wait For The Process To Finish To Start Another Process
When the user clicks on my button, it performs two functions: sending an SMS and sending an email. When I click on this button, the SMS is being sent and suddenly the email choose
Solution 1:
As per your code you have to wait for the SMS status or we can say Success or Failed Call back. You can do using Broadcast Receiver which will handle EVENT and return some feedback.
And you can call your email function after success of SMS.
Check Reference Example which is perfect for you.
If you need to monitor the status of the SMS message sending process, you can actually use two Pending Intent objects together with two BroadcastReceiver
objects, like this:
One for Sent SMS & Second for that Delivery status.
//---sends an SMS message to another device---privatevoidsendSMS(String phoneNumber, String message) {
StringSENT = "SMS_SENT";
StringDELIVERED = "SMS_DELIVERED";
PendingIntent sentPI = PendingIntent.getBroadcast(this, 0,
newIntent(SENT), 0);
PendingIntent deliveredPI = PendingIntent.getBroadcast(this, 0,
newIntent(DELIVERED), 0);
//---when the SMS has been sent---registerReceiver(newBroadcastReceiver() {@OverridepublicvoidonReceive(Context arg0, Intent arg1) {
switch (getResultCode()) {
caseActivity.RESULT_OK:
Toast.makeText(getBaseContext(), "SMS sent",
Toast.LENGTH_SHORT).show();
break;
caseSmsManager.RESULT_ERROR_GENERIC_FAILURE:
Toast.makeText(getBaseContext(), "Generic failure",
Toast.LENGTH_SHORT).show();
break;
caseSmsManager.RESULT_ERROR_NO_SERVICE:
Toast.makeText(getBaseContext(), "No service",
Toast.LENGTH_SHORT).show();
break;
caseSmsManager.RESULT_ERROR_NULL_PDU:
Toast.makeText(getBaseContext(), "Null PDU",
Toast.LENGTH_SHORT).show();
break;
caseSmsManager.RESULT_ERROR_RADIO_OFF:
Toast.makeText(getBaseContext(), "Radio off",
Toast.LENGTH_SHORT).show();
break;
}
}
}, newIntentFilter(SENT));
//---when the SMS has been delivered---registerReceiver(newBroadcastReceiver() {@OverridepublicvoidonReceive(Context arg0, Intent arg1) {
switch (getResultCode()) {
caseActivity.RESULT_OK:
Toast.makeText(getBaseContext(), "SMS delivered",
Toast.LENGTH_SHORT).show();
break;
caseActivity.RESULT_CANCELED:
Toast.makeText(getBaseContext(), "SMS not delivered",
Toast.LENGTH_SHORT).show();
break;
}
}
}, newIntentFilter(DELIVERED));
SmsManager sms = SmsManager.getDefault();
sms.sendTextMessage(phoneNumber, null, message, sentPI, deliveredPI);
}
Post a Comment for "Wait For The Process To Finish To Start Another Process"