I'm working on an android application that runs a servicio
in the background, I've been testing with different services and it happens that all of them run fine while the app runs normally, when I close the application the service will stop. Does anyone know why this happens?
public class serviceMusic extends Service{
private MediaPlayer med;
private Timer mTimer = null;
@Nullable
@Override
public IBinder onBind(Intent intent) {
return null;
}
@Override
public void onCreate() {
super.onCreate();
this.mTimer = new Timer();
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
med= MediaPlayer.create(this, R.raw.uci);
med.start();
return START_STICKY;
}
@Override
public void onDestroy() {
super.onDestroy();
med.stop();
}
}
logcat that generates when I close the app
04-11 08: 56: 54.133 2263-2263 / com.example.root.primera D / MediaPlayer: msg handleMessage: (4, 0, 0) 04-11 08: 57: 11.352 2263-2263 / com.example.root.primera D / OpenGLRenderer: Flushing caches (mode 0) 04-11 08: 57: 11.369 2263-2263 / com.example.root.primera D / ActivityThread: ACT-DESTROY_ACTIVITY handled: 1 / android.os.BinderProxy@41e082d0 04-11 08: 57: 11.369 2263-2263 /? D / ActivityThread: SVC-SERVICE_ARGS handled: 0 / ServiceArgsData{token=android.os.BinderProxy@41e98f08 startId = 2 args = Intent {act = android.intent.action.MAIN cat = [android.intent.category.LAUNCHER] flg = 0x10000000 cmp = com.example.root.primera / .MainActivity}}