I can’t fully understand how to make my IntentService call every N seconds and do certain actions in my browser. Googled this code:
Calendar cal = Calendar.getInstance(); Intent intent = new Intent(this, MyService.class); PendingIntent pintent = PendingIntent.getService(this, 0, intent, 0); AlarmManager alarm = (AlarmManager)getSystemService(ALARM_SERVICE); alarm.setRepeating(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), 1000 * 60, pintent); I call this code in the onCreate method of my main activation. But for some reason he does not work. How to implement it correctly?
Update: how correct will such a code be?
final Handler handler = new Handler(); final Runnable refresh = new Runnable() { public void run() { mServiceIntent = new Intent(MainActiviy.this, myService.class); startService(mServiceIntent); handler.postDelayed(this, 60000); } }; handler.post(refresh);