我有一个接收器。接收到BOOT_COMPLETED或START_BACKGROUND_SERVICE(自定义)的此接收器启动后台服务。启动服务后,如果不启动应用程序,我的后台服务内存使用量最多为25MB。如果我启动应用程序,美国的内存会无限高。
如果我没有启动后台服务并且只启动活动内存使用量就像20Mb。当两者都运行时,出现问题。
可能是什么问题?
这是后台服务;
public class OnClearFromRecentService extends Service {
@Override
public IBinder onBind(Intent intent) {
return null;
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
Log.d("ClearFromRecentService", "Service Started");
return START_NOT_STICKY;
}
@Override
public void onDestroy() {
super.onDestroy();
Log.d("ClearFromRecentService", "Service Destroyed");
}
@Override
public void onTaskRemoved(Intent rootIntent) {
Log.e("ClearFromRecentService", "END");
//Code here
stopSelf();
}}
此代码位于Receiver
中public class Receiver extends BroadcastReceiver {
Intent backgroundService;
@Override
public void onReceive(Context context, Intent intent) {
if (backgroundService == null){
backgroundService = new Intent(context, OnClearFromRecentService.class);
}
if (intent.getAction().equals("START_BACKGROUND_SERVICE")){
context.startService(backgroundService);
Log.i("TTW","STARTED");
}else if(intent.getAction().equals("STOP_BACKGROUND_SERVICE")){
context.stopService(backgroundService);
Log.i("TTW","STOPPED");
}else if(intent.getAction().equals("android.intent.action.BOOT_COMPLETED")){
context.startService(backgroundService);
Log.i("TTW","STARTED");
}else Log.i("TTW","NOTHING HAPPEN");
}}
可能是什么问题?请帮帮我。