I have to parse some data every day at 10 AM, and to put data in a ORMLite database. Which is proper way to do this? Should I use a service?
Asked
Active
Viewed 217 times
-3
-
1What have you tried so far? Did you google what to use for running background tasks? – Eugen Pechanec Aug 07 '16 at 20:18
-
Yes, I did. But I don't understand which is the best way, I found so many options. – Filip Rosca Aug 08 '16 at 06:52
2 Answers
0
Try this if it helps you out,
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.HOUR_OF_DAY, 10); // For 10 AM
calendar.set(Calendar.MINUTE, 0);
calendar.set(Calendar.SECOND, 0);
PendingIntent pi = PendingIntent.getService(context, 0,
new Intent(context, MyClass.class),PendingIntent.FLAG_UPDATE_CURRENT);
AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
am.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(),
AlarmManager.INTERVAL_DAY, pi);

Harshal Benake
- 2,391
- 1
- 23
- 40
-
-
In that case you need to manage proper context no main method is needed. – Harshal Benake Aug 07 '16 at 18:01
-
I did not understand too well, when I should call the update method? – Filip Rosca Aug 07 '16 at 19:07
-
@FilipRosca MyClass extends Service. Google how to implement a Service on Android. – Eugen Pechanec Aug 07 '16 at 20:18
-
@Eugen Pechanec but here is a problem, what if at 10 AM network will not be available? – Filip Rosca Aug 08 '16 at 06:55
-
-1
-
How? Please include code. See http://stackoverflow.com/help/how-to-answer Thank you. – Eugen Pechanec Aug 07 '16 at 20:17