سؤال

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
}

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();
}

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.

هل كانت مفيدة؟

المحلول

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.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top