Android 运行服务的巨大规模
我的应用程序有一个后台服务,该服务在MainActivity中使用以下代码进行调度:Android 运行服务的巨大规模,android,android-service,Android,Android Service,我的应用程序有一个后台服务,该服务在MainActivity中使用以下代码进行调度: Intent myIntent = new Intent(MainActivity.this , CheckUpdateService.class); AlarmManager alarmManager = (AlarmManager)getSystemService(ALARM_SERVICE); PendingIntent pendingIntent = PendingIntent.
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
这是我的检查更新服务
:
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);
}
}
}
一切都很好,但当我进入设置->应用程序->运行选项卡1小时后,我看到我的服务出现在列表的第一个位置,大小从10MB到20MB(取决于设备类型)。
和这不是全部。此服务持续增长,24小时后大小为:15MB到30MB(取决于设备类型)
问题是什么?我该如何解决这个问题?我必须小心点吗?
提前感谢。显然,您下载的JSON数据正在积累somewhere@Arnab谢谢你的回复。我如何检查并销毁它?