1

I have a service that I am trying to run constantly as long as the user has it on. The problem is the service uses a ton of memory; I'm guessing because it notifies the users and displays images constantly. So I put the bulk of my code in another activity. The service just calls the activity.

The issue is that I'm trying to use the return Start_Sticky to restart the service when it needs to. It takes about 2 hours before it uses up enough memory to need to restart. When it does restart it doesn't do the onStartCommand am I missing something?

public class AUTOAlarmService extends Service {
@Override
public void onCreate() {
}

@Override
public IBinder onBind(Intent intent) {
    return null;
}

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    Intent DI = new Intent(getBaseContext(), AUTOSERVICES.class);
    DI.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    getApplication().startActivity(DI);
    return START_STICKY;
}

@Override
public boolean onUnbind(Intent intent) {
    return super.onUnbind(intent);
}

}

4

1 回答 1

1

我认为您应该重新考虑已完成的一些工作,因为您的服务占用了太多资源,而这不应该以任何方式发生。有很多应用程序有很多服务,但没有重启设备的问题。

但是,如果要重新启动服务,则必须停止然后重新启动该服务。

stopService(new Intent(this, YourService.class));
startService(new Intent(this, YourService.class));

希望能帮助到你。

于 2013-08-06T22:30:23.887 回答