相关疑难解决方法(0)

启动时Android BroadcastReceiver - 当Activity在Background中时继续运行

我正在监控收到的短信.

我的应用程序与a完美配合BroadcastReceiver.但它是从一个Activity开始工作,并希望一直保持BroadcastReceiver运行(而不仅仅是我的Activity运行时).

我怎样才能做到这一点?我已经查看了生命周期,BroadcastReceiver但文档中提到的所有内容都是生命周期仅限于onReceive方法,而不是保持BroadcastReceiver检查传入SMS 的生命周期.

我怎么能坚持这个?

谢谢

android broadcastreceiver

51
推荐指数
2
解决办法
7万
查看次数

在Android 4上重复通知

目标:如果满足某些条件,通知每天下午2点出现一次.

示例:为简单起见,我们考虑每天都满足使用Internet连接检查的条件.如果今天已经在下午2点之后,我们将从明天开始通知.例如,用户在星期一下午4点启动应用程序,并在周二下午2点,周三下午2点,周四下午2点获得通知,依此类推.

问题:下午2点有第一个通知,但随后我会一遍又一遍地收到相同的通知.

问题似乎只在Android> = 4.0上.它在早期的机器人上运行良好.

这是我发送通知的方式:

public class NotifyService extends Service
{       
static final int NOTIFICATION_ID = 1;
// ...

@Override
public IBinder onBind(Intent intent)
{
    return null;
}

@Override
public int onStartCommand(Intent intent, int flags, int startId)
{
    try
    {
        Symbol biggest = getBiggestMover();
        if (biggest != null)
        {
            String title = getString(R.string.app_name);
            String text = getNotificationText(biggest.symbol, biggest.change);
            sendNotification(title, text);
        }
    }
    catch (Exception e)
    {
        // If there is Internet problem we do …
Run Code Online (Sandbox Code Playgroud)

notifications android alarmmanager

5
推荐指数
1
解决办法
2610
查看次数