0

这是我设置闹钟的代码:

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还是其他什么?我已经努力但未能找到任何解决方案。

4

1 回答 1

0

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

于 2013-03-05T11:17:59.173 回答