AlarmManager工作,以及在仿真器,但不是在真实设备是在、仿真器、但不、真实

2023-09-04 04:17:10 作者:人亦散、花亦落

这是我的code设置报警:

this is my code for setting alarm:

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梅索德:

this is my onRecieve methode:

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 或别的什么吗? 我已经很努力,但未能找到任何解决方案。

this is working well with emulator. at the same time i set an alarm which will trigger after 24 hour in emulator and real device. the work is done by the emulator well, but not in real device. is this happening for PowerManager.FULL_WAKE_LOCK or anything else? i have tried hard but failed find any solution.

推荐答案

对不起你们,问题在 PostManager 。在 PostManager ,我被检查与另一个字符串会话cookie。那么什么情况呢?这里是answwer。前4小时会话cookie留在cookiemanager所以检查通过 .equal(another_string)做工精细。但我认为,经过4个小时的会话cookie过期, .equal(another_string)抛出NullPointerException。所以我刚才检查的cookie我已经得到的,为空或不是。这解决了我的问题。再次对不起你们。

sorry guys, the problem was in PostManager. in PostManager, i was checking a session cookie with another string. so what happen? here is the answwer. before 4 hour the session cookie remain on cookiemanager so the checking by .equal(another_string) work fine. but i think after 4 hours the session cookie expire and .equal(another_string) throw a NullPointerException. so i have just check that the cookie i have get, is null or not. this solve my problem. again sorry guys.