巨大的运行服务规模

时间:2014-11-26 10:57:35

标签: android android-service

我的应用程序有一个后台服务,它使用MainActivity中的代码安排它:

    Intent myIntent = new Intent(MainActivity.this , CheckUpdateService.class);
    AlarmManager alarmManager = (AlarmManager)getSystemService(ALARM_SERVICE);
    PendingIntent pendingIntent = PendingIntent.getService(MainActivity.this, 0, myIntent, 0);
    Calendar calendar = Calendar.getInstance();
    calendar.set(Calendar.HOUR_OF_DAY, 12);
    calendar.set(Calendar.MINUTE, 00);
    calendar.set(Calendar.SECOND, 00);
    alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), 24*60*60*1000 , pendingIntent);  //set repeating every 24 hours

这是我的CheckUpdateService

public class CheckAppsUpdateService extends Service {

private GetJSONData update_notif_service;

public CheckAppsUpdateService() {
}

@Override
public IBinder onBind(Intent intent) {
    //throw new UnsupportedOperationException("Not yet implemented");
    return null;
}

@Override
public void onStart(Intent intent, int startId) {
    super.onStart(intent, startId);
}

@Override
public int onStartCommand(Intent intent, int flags, int startId) {

    ConnectionStatusDetector csd = new ConnectionStatusDetector(this);

    if (csd.isConnectingToInternet()) {
        try {
            // execute an asycntask here for getting Json data from server
        }catch (Exception e){
            Log.e("Update service error", "nothing");
        }
    }
    return super.onStartCommand(intent, flags, startId);
}

@Override
public void onDestroy() {
    super.onDestroy();
    if (update_notif_service != null && update_notif_service.getStatus() == AsyncTask.Status.RUNNING) {
        update_notif_service.cancel(true);
    }
}
}

一切都很完美,但是当我进入Setting->Apps->Running标签1小时后,我看到我的服务在列表的第一位,大小为10MB到20MB(取决于设备的类型)。
这不是一切。这项服务不断增长,以便在24小时后大小为:15MB到30MB(取决于设备的类型)!!!!

什么是问题?我该如何解决?我必须小心一些事吗?


提前谢谢。

0 个答案:

没有答案