2016-09-12 5 views

답변

0

당신은 필요에 따라 onStartCommand에서 START_STICKY 또는 START_REDELIVER_INTENT 중 하나를 반환해야처럼

public class MyService extends Service { 
public MyService() { 
} 

@Nullable 
@Override 
public IBinder onBind(Intent intent) { 
    // TODO: Return the communication channel to the service. 
    return null; 
} 


@Override 
public int onStartCommand(Intent intent1, int flags, int startId) { 
    // do your jobs here 
    return super.onStartCommand(intent1, flags, startId); 
} 
0

당신은, 끈적 서비스를 반환해야합니다.

그런 다음 서비스를 시작 단순히 START_STICKY 플래그를 반환 할 어떤 의도를 전달하지 않을 경우, 개발자 사이트에 명시된 바와 같이
public class MyService extends Service { 
    public MyService() { 
    } 

    @Nullable 
    @Override 
    public IBinder onBind(Intent intent) { 
      // TODO: Return the communication channel to the service. 
      return null; 
    } 


    @Override 
    public int onStartCommand(Intent intent1, int flags, int startId) { 
      // do your jobs here 
      return START_STICKY; 
    } 

} 

. 이렇게하면 빈 인 텐트 객체로 서비스가 다시 생성됩니다.

관련 문제