AlarmManager在模拟器中运行良好,但在真实设备中运行不正常

时间:2013-03-03 15:13:25

标签: android alarmmanager wakelock powermanager

这是我设置闹钟的代码:

public void SetAlarm(Context context, int tag, long time){
     AlarmManager am=(AlarmManager)context.getSystemService(Context.ALARM_SERVICE);
     Intent i = new Intent(context, Alarm.class);
     i.putExtra("position", tag);
     PendingIntent pi = PendingIntent.getBroadcast(context, tag, i, PendingIntent.FLAG_CANCEL_CURRENT);
     am.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis()+ time, pi); // Millisec * Second * Minute
}

这是我的onRecieve方法:

public void onReceive(final Context context, Intent intent){   
    PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
    PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK, "my wak up lo");
    wl.acquire();

    position = intent.getIntExtra("position", -1);         
    new PostManager(context, position);

    wl.release();
}

这适用于模拟器。同时我设置了一个警报,它会在模拟器和真实设备中24小时后触发。这项工作很好地由模拟器完成,但不是在真实设备中完成。这是PowerManager.FULL_WAKE_LOCK还是其他什么事情发生的? 我努力但失败了找到任何解决方案。

1 个答案:

答案 0 :(得分:0)

抱歉,伙计们问题出在PostManager。在PostManager中,我正在使用另一个字符串检查会话cookie。那会发生什么?这是答案。在4小时之前,会话cookie保留在cookiemanager上,因此.equal(another_string)的检查工作正常。但我想4小时后会话cookie过期,.equal(another_string)抛出NullPointerException。所以我只检查我得到的cookie,是否为空。这解决了我的问题。再次抱歉,伙计们。

相关问题