java alertdialog_java – 如何让AlertDialog框出现在应用程序之...

@Override

public void run() {

//Create thread that can alter the UI

AlarmPage.this.runOnUiThread(new Runnable() {

public void run() {

cal = Calendar.getInstance();

//See if current time matches set alarm time

if((cal.get(Calendar.HOUR_OF_DAY) == alarmTime.getCurrentHour())

&& (cal.get(Calendar.MINUTE) == alarmTime.getCurrentMinute())){

//If the sound is playing, stop it and rewind

if(sound.isPlaying()){

ShowDialog();

alarmTimer.cancel();

alarmTask.cancel();

alarmTask = new PlaySoundTask();

alarmTimer = new Timer();

alarmTimer.schedule(alarmTask, sound.getDuration(), sound.getDuration());

}

sound.start();

}

}

});

}

public void ShowDialog() {

final AlertDialog.Builder alertDialog = new AlertDialog.Builder(this);

alertDialog.setTitle("REMINDER!");

alertDialog.setMessage("Turn off alarm by pressing off");

alertDialog.setNegativeButton("Off", new DialogInterface.OnClickListener(){

@Override

public void onClick(DialogInterface dialog, int which) {

Toast.makeText(getApplicationContext(), "OFF", Toast.LENGTH_SHORT);

}

});

alertDialog.show();

}

我正在制作一个通知用户的简单闹钟应用程序.我想制作一个警告框,让用户可以选择在闹钟响起时关闭闹钟.我能够制作警报框,但它只出现在不在应用程序之外的应用程序中.我知道应用程序必须在后台运行.如果我需要显示更多代码或更具体,请询问.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值