我一個人應該避免使用完成()的文檔閱讀 - 但我實在看不出這個更好的選擇......替代完成()
我只是想知道,如果有是一個更好的,更清潔的方式做到這一點...
非常感謝
這就是我基本上需要做的:
MainActivity
-> Sub1Activity
-> MySMSActivity
-> send SMS
-> handle if SMS was sent or not
<- finish()
<- finish()
(skip Sub1Activity)
MainActivity
在MainActi代碼VITY:
this.myBtn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
doSub1Activity("xyz");
}
});
public void doSub1Activity() {
Intent i;
i = new Intent(this, SUB1_screen.class);
startActivity(i);
}
中的代碼Sub1Activity:
this.myBtn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
doMySMSActivity("xxx");
finish(); //<- this is the 1. call to "finish" I am concerned about
}
public void doMySMSActivity() {
Intent i;
i = new Intent(this, MySMSActivity.class);
startActivity(i);
}
中的代碼MySMSActivity:
private void sendSMS(String phoneNumber, String message)
{
String SENT = "SMS_SENT";
String DELIVERED = "SMS_DELIVERED";
PendingIntent sentPI = PendingIntent.getBroadcast(this, 0,
new Intent(SENT), 0);
//---when the SMS has been sent---
bRSMS_has_been_sent = new BroadcastReceiver(){
@Override
public void onReceive(Context arg0, Intent arg1) {
switch (getResultCode())
{
case Activity.RESULT_OK:
...
break;
default:
break;
}
finish(); // another call to finish so the user continues with
// MainActivity after SMS has been sent...
}
};
SmsManager sms = SmsManager.getDefault();
sms.sendTextMessage(phoneNumber, null, message, sentPI, deliveredPI);
}
您能鏈接到文檔嗎? – Ally