본문 바로가기

프로그래밍/Android

Android Service 관련 이슈(롤리팝 이상)

상황

기존 프로젝트는 Eclipce ADT + Kitkat Version에서 돌아가고 있었다.
해당 프로젝트를 Android Studio로 마이그레이션 하다 생긴 이슈이다.

문제점

Run을 하는 순간 애플리케이션이 죽어버리는 최악의 상황이다.
로그를 보자. (보안을 위해 프로세스명은 가렸다.)

Process: com.security, PID:
java.lang.RuntimeException: Unable to create application com.security.app.App: java.lang.IllegalStateException: Not allowed to start service Intent { pkg=com.sec.security cmp=com.security/.service.securityService }: app is in background uid UidRecord

대충 해석을 해보면 service Intent를 시작할 수 없다는 내용이다.

해결법

매우 간단하다. 우리 StackOverflow 형님들은 항상 답을 알고 있다.

기존 코드

Intent service = new Intent(com.security);
mContext.bindService(service, mCon, 1);

변경한 코드

Intent service = new Intent(com.security);
service.setPackage(com.security);
mContext.bindService(service, mCon, 1);

targetSdkVersion을 21 이상 올릴 경우 intent에 따로 package를 설정해줘야 한다.

후기

레거시 코드를 현대화 하는 작업은 너무 빡세다.

'프로그래밍 > Android' 카테고리의 다른 글

[Kotlin] Idioms (관용구)  (0) 2021.08.25
[Kotlin] Basic syntax (기본 구문)  (0) 2021.08.24
Android RecylerView 새로고침 & 데이터 추가  (0) 2021.07.28
Activity Lifecycle  (0) 2021.03.17
Activity  (0) 2021.03.17