如何弹出无任何背景的活动报警消息? [英] How to popup Alarm Message without any activity in background?

查看:269
本文介绍了如何弹出无任何背景的活动报警消息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的Andr​​oid应用程式我我可以报警功能和以及注销功能。我设定闹钟时间后,我被点击注销按钮退出应用程序。

In my android i app i can alarm functionality and as well logout functionality. After setting my alarm time i am exiting the app by clicking the logout button.

我使用

         ExitActivity.this.finish();  
         Intent intent1 = new Intent(ExitActivity.this,PinActivity.class);  
         intent1.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);   
         startActivity(intent1);  

         Intent intent = new Intent(Intent.ACTION_MAIN); 
         intent.addCategory(Intent.CATEGORY_HOME);  
         intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 
         startActivity(intent); 

这code退出应用程序,都到家里引脚屏幕之后,它启动主屏幕。这是因为,当我回来我的应用程序就启动pinscreen。报警的工作正是我想要的,但报警时弹出消息它在后台pinactivity(我不希望)。我wan't在后台摆脱出来的销活动。

this code to exit the app,which goes to home pin screen and after that it launches the home screen. This is because when i am coming back to my app it launches the pinscreen. Alarm working exactly what i want but while alarm popup message it has the pinactivity in the background(which i don't want). I wan't to get rid out of the pin activity in the background.

这是我的接收器类?

     public class ShortTimeEntryReceiver extends BroadcastReceiver{

     @Override
     public void onReceive(Context context, Intent intent) {

    Toast.makeText(context,"Alarm Working", Toast.LENGTH_SHORT).show();

     try {
         Bundle bundle = intent.getExtras();
         String message = bundle.getString("alarm_message");

         Intent newIntent = new Intent(context, ReminderPopupMessage.class);
         newIntent.putExtra("alarm_message", message);
         newIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
         context.startActivity(newIntent);
        } catch (Exception e) {
         Toast.makeText(context, "There was an error somewhere, but we still received an alarm", Toast.LENGTH_SHORT).show();
         e.printStackTrace();

        }
}

我该怎么办呢?
感谢您的帮助家伙..

How do i do that? Thanks for your help guys..

推荐答案

您应该使用报警管理器在Android中设置闹钟。报警经理握着你的报警及消防报警时间待定意图。

You should use Alarm Manager to set alarms in Android. The alarm manager holds your alarm and fire an pending intent on alarm time.

首先,创建这样一个未决的意图:

First create a pending intent like this :

 pendingIntent = PendingIntent.getService(CONTEXT, ALARM_ID,  INTENT_TO_LAUNCH, 0);

然后用这个悬而未决的意图来设置这样一个报警:

Then use this pending intent to set an Alarm like this :

 AlarmManager alarmManager = (AlarmManager)getSystemService(ALARM_SERVICE);
 alarmManager.set(AlarmManager.RTC_WAKEUP, ALARM_TIME, pendingIntent);

这将在给定的时间开始挂起的意图。

This will start the pending intent at given time.

要删除警报,你必须重新创建具有相同ALARM_ID相同挂起意图:

To remove an alarm you have to recreate the same Pending Intent with same ALARM_ID :

 alarmManager.cancel(pendingIntent);

这篇关于如何弹出无任何背景的活动报警消息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆