From 7199a92e854d91b5fc19c30379da821b6d03dd7b Mon Sep 17 00:00:00 2001 From: gq <15933486098@qq.com> Date: Wed, 14 May 2025 23:09:54 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B3=A8=E9=87=8A=E4=BA=86onClick=E6=96=B9?= =?UTF-8?q?=E6=B3=95,onDismiss=E6=96=B9=E6=B3=95=E5=92=8CstopAlarmSound?= =?UTF-8?q?=E6=96=B9=E6=B3=95~?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../micode/notes/ui/AlarmAlertActivity.java | 24 ++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/Notesmaster/app/src/main/java/net/micode/notes/ui/AlarmAlertActivity.java b/Notesmaster/app/src/main/java/net/micode/notes/ui/AlarmAlertActivity.java index f32b267..7e0e8ba 100644 --- a/Notesmaster/app/src/main/java/net/micode/notes/ui/AlarmAlertActivity.java +++ b/Notesmaster/app/src/main/java/net/micode/notes/ui/AlarmAlertActivity.java @@ -169,29 +169,51 @@ public class AlarmAlertActivity extends Activity implements OnClickListener, OnD dialog.show().setOnDismissListener(this); } + /** + * 处理对话框按钮点击事件 + * @param dialog 触发事件的对话框对象 + * @param which 被点击的按钮标识 + */ public void onClick(DialogInterface dialog, int which) { switch (which) { case DialogInterface.BUTTON_NEGATIVE: + // 当点击否定按钮(如"进入"按钮)时: + // 1. 创建跳转到笔记编辑页面的Intent Intent intent = new Intent(this, NoteEditActivity.class); + // 2. 设置动作为查看 intent.setAction(Intent.ACTION_VIEW); + // 3. 传入当前笔记ID作为额外数据 intent.putExtra(Intent.EXTRA_UID, mNoteId); + // 4. 启动笔记编辑Activity startActivity(intent); break; default: + // 其他按钮(如确定按钮)不做特殊处理 break; } } + /** + * 对话框关闭时的回调方法 + * @param dialog 被关闭的对话框对象 + */ public void onDismiss(DialogInterface dialog) { + // 1. 停止闹铃声音 stopAlarmSound(); + // 2. 关闭当前Activity finish(); } + /** + * 停止并释放闹铃播放器资源 + */ private void stopAlarmSound() { if (mPlayer != null) { + // 停止播放 mPlayer.stop(); + // 释放播放器资源 mPlayer.release(); + // 将播放器引用置空,防止内存泄漏 mPlayer = null; } } -}