无法停止其他活动的响铃警报

编程入门 行业动态 更新时间:2024-10-26 22:22:22
本文介绍了无法停止其他活动的响铃警报的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我是android的新手,这里我正在练习我的第一个应用程序(警报应用程序)。

I am new to android ,Here I am practicing my first app (Alarm App).

我的应用程序中存在一个问题,我无法停止警报一旦触发,警报就不会停止。

I have an issue in my app that I can't stop the alarm once a alarm is triggered it's keep on ringing can't get stopped.

在我的应用中,我有2个活动和一个AlarmReceiver。

In my app I have 2 activities and a AlarmReceiver .

在AlarmActivity.java中,我已经设置了警报,到达特定时间后,Alarmreceiver.java将被触发,警报开始响起并显示唤醒屏幕。

From the AlarmActivity.java I have set the alarm ,when the specific time is reached the Alarmreceiver.java will get triggered and the alarm started to ring and showing a wakeup screen .

在WakeUpScreen.java中,我有一个停止按钮,需要停止当前的响铃警报。

From the WakeUpScreen.java I have a stop button by using that I need to stop the current ringing alarm .

我没有

AlarmActivity.java

AlarmActivity.java

public void stopAlarm(Context context) { Intent intent = new Intent(context,AlarmReceiver.class); intent.setAction("ALARM_OFF"); PendingIntent pendingIntent = PendingIntent.getBroadcast(context, mAlarmId, intent,PendingIntent.FLAG_UPDATE_CURRENT); AlarmManager alarmManager = (AlarmManager) context.getSystemService(ALARM_SERVICE); alarmManager.cancel(pendingIntent); }

我在AlarmActivity.java中有这个AlarmStop()函数,它将被点击当我按下wakeupscreen.java中的停止按钮时。

I have this AlarmStop() function in my AlarmActivity.java which will get hit when I press the stop button in wakeupscreen.java

当我尝试调试停止过程时,调试器将stopAlarm()函数中的所有行都移了,但是Intent不起作用,这就是为什么没有调用AlarmReceiver.java文件的原因,我的意思是,调试器移动了上述方法中的所有行,但没有调用AlarmReceiver.java

我尝试了很多方法来解决此问题,但我错过了一些我无法解决的问题。

I tried lot of ways to solve this but I missed something that I can't figured it out.

有人可以帮我停下来吗?

Can anyone help me to stop the triggered alarm and it's ringing sound .

推荐答案

您的体系结构已损坏。您无需使用 BroadcastReceiver 进行持久处理。 BroadcastReceiver 的生命周期很短,您可以用它触发其他事情。

Your architecture is broken. You don't use a BroadcastReceiver for persistent processing. A BroadcastReceiver has a very short lifecycle, you use it to trigger other things.

您已经创建了<您的 BroadcastReceiver 中的code> MediaPlayer 实例,并试图在 onReceive()。错了您应该使用服务来管理和维护 MediaPlayer 的状态。

You've created a MediaPlayer instance in your BroadcastReceiver and are trying to control that in onReceive(). This is wrong. You should use a Service to manage and maintain the state of your MediaPlayer.

看看是否可以在Internet上找到有关如何构建这样的应用程序的HOWTO指南。

See if you can find some HOWTO guides on the Internet for how to build such an application.

更多推荐

无法停止其他活动的响铃警报

本文发布于:2023-11-27 10:36:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1637723.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:响铃   警报

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!