Android 我应该每天使用AsyncTask或IntentService通过URL更新一次日期吗?

Android 我应该每天使用AsyncTask或IntentService通过URL更新一次日期吗?,android,android-asynctask,android-service,Android,Android Asynctask,Android Service,在我的应用程序中,我使用AsyncTask从URL获取数据。通过这个URL,我每天都用一些新数据更新我的应用程序。 但是,我想知道哪个是最适合我的AsyncTask或IntentService通过URL更新数据并每天下载一次?假设您已启动并运行IntentService 每天给你的服务中心打一次电话 Intent myIntent = new Intent(context, MyServiceReceiver.class); PendingIntent pendingIntent = P

在我的应用程序中,我使用
AsyncTask
从URL获取数据。通过这个URL,我每天都用一些新数据更新我的应用程序。

但是,我想知道哪个是最适合我的
AsyncTask
IntentService
通过URL更新数据并每天下载一次?

假设您已启动并运行IntentService

每天给你的服务中心打一次电话

  Intent myIntent = new Intent(context, MyServiceReceiver.class);
  PendingIntent pendingIntent = PendingIntent.getBroadcast(context,  0, myIntent, 0);

  AlarmManager alarmManager = (AlarmManager)context.getSystemService(Context.ALARM_SERVICE);
  Calendar calendar = Calendar.getInstance();
  calendar.setTimeInMillis(System.currentTimeMillis());
  calendar.add(Calendar.SECOND, 60); // first time
  long frequency= 86400000 * 1000; // every 24 hours
  alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), frequency, pendingIntent);    

检查此站点以比较服务、线程、IntentService和


但就我个人而言,我认为你应该使用一个.

创建服务来实现AlarmManager,它可以在一天内运行一个@Murtaza Hussain。你有任何演示代码吗…??我将此作为一个答案发布,希望能有所帮助