Android AlarmManager Service

I have a little problem ... more than anything else, I need some tips and examples. I need to compare 2 lines, one of which is received from the current date on the device, the other is the date that I am writing. therefore, this comparison can be done at any time .. this comparison, if true, executes a different command.

I created an AlarmManager that calls the loop one service, and there is a comparison in this service that I need.

private static final int EXEC_INTERVAL = 10 * 1000;

Intent myIntent = new Intent(AndroidAlarmService.this, MyAlarmService.class);
   pendingIntent = PendingIntent.getService(AndroidAlarmService.this, 0, myIntent, 0);

            AlarmManager alarmManager = (AlarmManager)getSystemService(ALARM_SERVICE);

            Calendar calendar = Calendar.getInstance();
            calendar.setTimeInMillis(System.currentTimeMillis());
            calendar.add(Calendar.SECOND, 10);

            alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), EXEC_INTERVAL,  pendingIntent);

Which method is better to do what I need?

Am i using this? or do you need a BroadcastReceiver?

if you can give me some examples, very grateful .. thanks in advance!

+3
source share
1 answer

, 10 "MyAlarmService", ?

, - Handler, AlarmManager. android (http://developer.android.com/reference/android/app/AlarmManager.html), Handler .

, , . - , , , .

, : http://www.vogella.com/articles/AndroidPerformance/article.html

:

Handler handler = new Handler();
handler.postDelayed(new Runnable() { /* comparison work */ }, EXEC_INTERVAL);
+3

All Articles