如何停止报警android应用

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

我已经开发出remindes用户每10分钟alertDialog在2小时内申请ONLY,

I've to develop an application that remindes the user every 10 minutes with alertDialog during 2 hours ONLY,

我做了提醒用户,每次10分钟的应用程序,但我想2小时后停止它实际上我不能这样做,

I made an application that reminds a user for each 10 minutes, but I want to stop it after 2 hour actually I couldn't do that,

我搜查,但没有答案,如果我用amManger.cancel();它会2小时前取消报警:(那么,有没有办法做到这一点?并请给出一个expamle因为我是新到Android ...

I searched but no answers, if I used amManger.cancel(); it'll cancel the alarm before 2 hour :"( so, is there any way to do that ? and please give an expamle as I'm new to android...

由于alooooot ..

thanks alooooot ..

--------------更新后---------------------------

-------------- After Updating ---------------------------

public class MyAlarm extends Activity { private PendingIntent pendingIntent; int i = 1; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); Button buttonStart = (Button) findViewById(R.id.startalarm); Button buttonCancel = (Button) findViewById(R.id.cancelalarm); Button bCancel= (Button) findViewById(R.id.button1); pendingIntent = PendingIntent.getService(MyAlarm.this, 0, new Intent(MyAlarm.this, MyAlarmService.class), 0); buttonStart.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { // TODO Auto-generated method stub long firstTime = SystemClock.elapsedRealtime(); AlarmManager am = (AlarmManager) getSystemService(ALARM_SERVICE); AlarmManager am2 = (AlarmManager) getSystemService(ALARM_SERVICE); am.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, firstTime + 10 * 1000, 10 * 1000, pendingIntent); } }); bCancel.performClick();

问题: - 我应该在哪里把code停止报警时bCancel按钮自动点击?

Question: - Where should I put the code to stop the alarm when the bCancel button clicked automatically ??

- 和我怎样才能使这个点击后两小时???

-and how can I make this click after two hours ???

感谢,

推荐答案

试试这个 -

final Button bCancel= (Button) findViewById(R.id.button1); bCancel.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { //Your code to stop the alarm goes here. } }); new Handler().postDelayed(new Runnable() { @Override public void run() { bCancel.performClick(); } }, (2*60*60*1000));

更多推荐

如何停止报警android应用

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

发布评论

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

>www.elefans.com

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