Android프로그래밍

[안드로이드 스튜디오] Caused by: android.app.StackTrace: Last startServiceCommon() call for this service was made here 오류

앱 업데이트를 위해 안드로이드스튜디오에서 앱을 실행을 반복하다면 , 포그라운드 서비스 오류가 발생한다. 왜???

지금까지 본적 없는 오류이다.


                                                                                                    android.app.RemoteServiceException$ForegroundServiceDidNotStartInTimeException: Context.startForegroundService() did not then call Service.startForeground(): ServiceRecord{513e5e9 u0 com.test.testSevcie/.testSevcie}
                                                                                                    	at android.app.ActivityThread.generateForegroundServiceDidNotStartInTimeException(ActivityThread.java:2315)
                                                                                                    	at android.app.ActivityThread.throwRemoteServiceException(ActivityThread.java:2286)
                                                                                                    	at android.app.ActivityThread.-$$Nest$mthrowRemoteServiceException(Unknown Source:0)
                                                                                                    	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2611)
                                                                                                    	at android.os.Handler.dispatchMessage(Handler.java:106)
                                                                                                    	at android.os.Looper.loopOnce(Looper.java:230)
                                                                                                    	at android.os.Looper.loop(Looper.java:319)
                                                                                                    	at android.app.ActivityThread.main(ActivityThread.java:8893)
                                                                                                    	at java.lang.reflect.Method.invoke(Native Method)
                                                                                                    	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:608)
                                                                                                    	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1103)
                                                                                                    

Caused by: android.app.StackTrace: Last startServiceCommon() call for this service was made here
                                                                                                    	at android.app.ContextImpl.startServiceCommon(ContextImpl.java:2023)
                                                                                                    	at android.app.ContextImpl.startForegroundService(ContextImpl.java:1967)
                                                                                                    	at android.content.ContextWrapper.startForegroundService(ContextWrapper.java:847)
                                                                                                    	at android.content.ContextWrapper.startForegroundService(ContextWrapper.java:847)
                                                                                                    	at com.test.MainActivity$$ExternalSyntheticApiModelOutline0.m(R8$$SyntheticClass:0)
                                                                                                    	at com.test.MainActivity.backgroudServiceRestart(MainActivity.java:859)
                                                                                                    	at com.test.MainActivity.MainActivity.checkAndroid13(MainActivity.java:668)
                                                                                                    	at com.test.MainActivity.onCreate(ProMainActivity.java:507)
                                                                                                    	at android.app.Activity.performCreate(Activity.java:8944)
                                                                                                    	at android.app.Activity.performCreate(Activity.java:8913)
                                                                                                    	at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1456)
                                                                                                    	at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:4146)
                                                                                                    	at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:4322)
                                                                                                    	at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:103)
                                                                                                    	at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:139)
                                                                                                    	at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:96)
                                                                                                    	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2685)
                                                                                                    	at android.os.Handler.dispatchMessage(Handler.java:106) 
                                                                                                    	at android.os.Looper.loopOnce(Looper.java:230) 
                                                                                                    	at android.os.Looper.loop(Looper.java:319) 
                                                                                                    	at android.app.ActivityThread.main(ActivityThread.java:8893) 
                                                                                                    	at java.lang.reflect.Method.invoke(Native Method) 
                                                                                                    	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:608) 
                                                                                                    	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1103) 

나와 동일한 이슈가 발생한 개발자가 있는데, 해결책은 딱히 안보인다.

https://github.com/doublesymmetry/react-native-track-player/issues/2156

오류가 발생한 코드는 다음과 같다.

            if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU){ 
                boolean isRunning = isServiceRunningCheck();
                if (!isRunning) {
                    startForegroundService(new Intent(MainActivity.this, TestService.class));
                }
            } else {
                Intent intent = new Intent(MainActivity.this, TestService2.class);
                //intent.putExtra("request_stop", false);
                //service 시작
                boolean isRunning = isServiceRunningCheck();
                if (!isRunning) {
                    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
                        startForegroundService(intent);
                    } else {
                        startService(intent);
                    }
                }
            }

테스트 폰에서 설치 삭제하고 다시 앱을 실행하면 정상적으로 포그라운드 서비스가 다시 올라오긴한다.

그런데 만약, 구글플레이에서 앱을 업데이트 후 이런 현상이 발생하는 경우가 생기지는 않겠지??

error: Content is protected !!