启动活动使用AlarmManager,没有了BroadcastReceiver没有了、AlarmManager、BroadcastReceiver

由网友(血之狂魔)分享简介:我希望有人给我一个答案:我不知道是否有可能(共同)使用AlarmManager直接开始一个活动。该文件没有明确说明这一点。这里只描述Broadcastreceivers的使用。如果有可能开始我的活动directy,我哪里会收到意向书(onNewIntent)?非常感谢让 - 皮埃尔·解决方案 我不知道是否有可能(共...

我希望有人给我一个答案:

我不知道是否有可能(共同)使用AlarmManager直接开始一个活动。该文件没有明确说明这一点。这里只描述Broadcastreceivers的使用。

如果有可能开始我的活动directy,我哪里会收到意向书(onNewIntent)?

非常感谢 让 - 皮埃尔·

解决方案   

我不知道是否有可能(共同)使用AlarmManager直接开始一个活动。

是的。

  

该文件没有明确说明这一点。这里只描述Broadcastreceivers的使用。

使用的BroadcastReceiver 是最常见的场景。这是必需的 _WAKEUP 报警,如果你希望设备可靠地醒来时,警报响起。

从开始 AlarmManager 的活动应该用于闹钟型应用程序,并没有别的。你不知道什么是用户可能会做的手机,当你的活动来到前台,他们可能会很生你的气,如果他们觉得你的入侵是没有道理的。

  

如果有可能开始我的活动directy,我哪里会收到意向书(onNewIntent)?

在默认情况下,该活动的新实例将被创建。如果你使用 FLAG_ACTIVITY_CLEAR_TOP FLAG_ACTIVITY_SINGLE_TOP ,它将提出活动的现有实例,你会得到的意图 onNewIntent()

数据驱动活动运营的理论与实务

这演示如何使用示例项目 AlarmManager 这种方式。 这演示用户可配置的活动 - 或 - 通知时,警报就会响起。这两者都是在一系列的教程比较深,所以应用程序是一个有点复杂。

I hope that someone has an answer for me:

I wonder if it is possible (and common) to use the AlarmManager for directly starting an Activity. The documentation does not explain this explicitly. It only describes the usage of Broadcastreceivers.

If it is possible to start my Activity directy, where will I receive the Intent (onNewIntent)?

Many thanks Jean-Pierre

解决方案

I wonder if it is possible (and common) to use the AlarmManager for directly starting an Activity.

Yes.

The documentation does not explain this explicitly. It only describes the usage of Broadcastreceivers.

Using a BroadcastReceiver is the most common scenario. It is required for _WAKEUP alarms, if you want the device to reliably wake up when the alarm goes off.

Starting an activity from AlarmManager should be used for "alarm clock"-type applications, and little else. You have no idea what the user might be doing with the phone when your activity comes to the foreground, and they may get very angry with you if they feel that your intrusion is unjustified.

If it is possible to start my Activity directy, where will I receive the Intent (onNewIntent)?

By default, a new instance of the activity will be created. If you use FLAG_ACTIVITY_CLEAR_TOP and FLAG_ACTIVITY_SINGLE_TOP, it will bring forward an existing instance of the activity, and you will get the Intent in onNewIntent().

This sample project demonstrates using AlarmManager this way. This sample project demonstrates user configurable Activity-or-Notification when the alarm goes off. Both of these are relatively deep in a series of tutorials, and so the apps are a bit complex.

阅读全文

相关推荐

最新文章