开发者

AlarmManager start service hourly every hour to download files (. Zip) entering timeout

I have a service that runs every hour by a shot in my AlarmManager startAPP.class (main activity) in onCreate, as follows:

Intent it = new Intent("SINC");
PendingIntent p = PendingIntent.getBroadcast(StartAPP.this, 0, it, 0);
Calendar c = Calendar.getInstance();
c.setTimeInMillis(System.currentTimeMillis());
c.add(Calendar.SECOND, inicio);

AlarmManager alarm = (AlarmManager) getSystemService(ALARM_SERVICE);
long time = c.getTimeInMillis();
alarm.setRepeating(AlarmManager.RTC_WAKEUP, time, repetir, p);

Everything ok. The service is triggered exactly as it should. But how is that a download is done execution is so开发者_Python百科mewhat slow (minutes) 1 or 2. And this time the android triggers a dialog stating that the application stopped responding and asks if I want to close or wait.

How do I get this service does not display this message (dialog). Because from what I read services are used for processing time consuming and downloading files.

The service extends BroadcastReceiver

public class Sinc extends BroadcastReceiver

Note: if I tell the dialog I want to wait, the whole service process is successfully completed. (all files are downloaded)

Thanks


You should have your Sinc class inherit from IntentService instead of BroadcastReceiver and modify your PendingIntent to be a service intent instead of a broadcast intent.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜