AlarmManager工作,以及在仿真器,但不是在真实设备 [英] AlarmManager working well in emulator but not in real device

查看:142
本文介绍了AlarmManager工作,以及在仿真器,但不是在真实设备的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的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.

这篇关于AlarmManager工作,以及在仿真器,但不是在真实设备的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆