我有一个一次调用两个方法的按钮。那就是alarm()和sms()。当我点击按钮时,AlertDialog 会出现,但在我按下“STOP”按钮之前就消失了。它消失后不久,我收到了短信。如果我按下后退按钮,AlertDialog 会再次出现。看来我出了车祸什么的。
onCreate() 方法:
btnAlarm = (Button) findViewById(R.id.btnAlarm);
btnAlarm.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
alarm();
sms();
}
});
警报()方法:
public void alarm()
{
Alarm1 = MediaPlayer.create(MySetting.this, R.raw.lingcoll);
//Turn on the alarm sound
Alarm1.setLooping(true); // Set looping
Alarm1.start();
AlertDialog.Builder builder = new AlertDialog.Builder(MySetting.this);
builder.setMessage(R.string.alert_stop)
.setIcon(android.R.drawable.ic_alert)
.setTitle(R.string.alert_dialog_warning)
.setCancelable( false )
.setPositiveButton(R.string.alert_btnStop, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
Alarm1.stop();
MySetting.isAlarm = false;
}
});
AlertDialog alert = builder.create();
alert.show();
}
短信()方法:
public void sms()
{
TextView a = (TextView) findViewById(R.id.txtPhoneNo);
String phoneNo = a.getText().toString();
String message = "My Application works!";
PendingIntent pi = PendingIntent.getActivity(this, 0,
new Intent(this, FinalSetting.class), 0);
SmsManager sms = SmsManager.getDefault();
sms.sendTextMessage(phoneNo, null, message, pi, null);
}
LogCat 看起来不错,所以我不知道是什么问题。有谁知道如何防止这种情况???非常感谢提前..