728x90
안드로이드 8.0 에서 서비스를 실행할 때 아래코드를 추가해줘야 에러가 발생하지 않는다.
// 서비스를 실행할 때
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
context.startForegroundService(new Intent(context, ServedService.class));
} else {
context.startService(new Intent(context, ServedService.class));
}
// 서비스 파일 내에서
@Override
public void onCreate() {
super.onCreate();
startForeground(1,new Notification()); // 추가
}
@Override
public void onDestroy() {
// 서비스가 종료될 때 실행
super.onDestroy();
stopForeground(true);
}
728x90
'안드로이드 > 버그탈출' 카테고리의 다른 글
com.github.nkzawa:socket.io-client 버전 (0) | 2018.09.19 |
---|---|
Android 8.0 background 실행 제한, 9.0 관련 사항 추가 (1) | 2018.08.25 |
compileSdkVersion (0) | 2018.08.08 |
Android Studio applicationId 변경 (0) | 2018.08.01 |
Android Studio 앱의 데이터 자동 백업을 막는 방법 (1) | 2018.07.30 |