Java 应用程序打开存储时中断函数SendSMSMessage
我有一个函数:Java 应用程序打开存储时中断函数SendSMSMessage,java,android,Java,Android,我有一个函数:protectedvoid sendSMSMessage()…,当倒计时达到0时,它会自动发送一条消息。 我想做的是,当我单击“后退”按钮时,中断该功能以不发送消息。 我的onDestroy中应该包含哪些内容 protected void onDestroy() { // Don't forget to shutdown! if (tts != null) { //tts= texttospeech (don't matter)
protectedvoid sendSMSMessage()…
,当倒计时达到0时,它会自动发送一条消息。
我想做的是,当我单击“后退”按钮时,中断该功能以不发送消息。
我的onDestroy
中应该包含哪些内容
protected void onDestroy()
{
// Don't forget to shutdown!
if (tts != null) { //tts= texttospeech (don't matter)
tts.stop();
tts.shutdown();
}
super.onDestroy();
mp.stop(); //mp=mediaplayer (don't matter)
}
这是我的职责:
protected void sendSMSMessage() {
Log.i("Send SMS", "");
/*
String phoneNo = txtphoneNo.getText().toString();
String message = txtMessage.getText().toString();
*/
String phoneNo = "000000000";
String message = "Teste";
try {
SmsManager smsManager = SmsManager.getDefault();
smsManager.sendTextMessage(phoneNo, null, message, null, null);
Toast.makeText(getApplicationContext(), "SMS sent.",
Toast.LENGTH_LONG).show();
finish();
} catch (Exception e) {
Toast.makeText(getApplicationContext(),
"SMS faild, please try again.",
Toast.LENGTH_LONG).show();
e.printStackTrace();
}
}
所以我想在单击backbutton时停止发送短信的功能
有什么建议吗?请以更清晰的方式提问。我们不知道什么是tts,mp…如果你想对后退按钮做出反应,我建议你使用onBackPressed回调方法。你的sendSMSMessage()和倒计时是什么样子的?你需要显示更多的urs代码。覆盖后退按钮以取消计时器。<注:上面显示了我提到的代码