ZahraHeydari / MusicPlayer

Implemented using Clean Arch, MVVM, LiveData, Room, Koin, Coil, Service, Notification and ExoPlayer
Apache License 2.0
618 stars 88 forks source link

Did not then call Service.startForeground() #7

Closed a1573595 closed 4 years ago

a1573595 commented 4 years ago

Hi, MusicPlayer need to call startForeground() when it use Foreground service.

2020-02-02 09:22:25.769 1534-1566/? E/ActivityManager: ANR in com.android.musicplayer PID: 10683 Reason: Context.startForegroundService() did not then call Service.startForeground() Load: 0.57 / 0.49 / 0.79 CPU usage from 29995ms to 0ms ago (2020-02-02 09:21:53.398 to 2020-02-02 09:22:23.393): 38% 1844/com.android.systemui: 32% user + 5.5% kernel / faults: 14150 minor 75 major 14% 696/surfaceflinger: 8.4% user + 6.3% kernel / faults: 581 minor 13 major 13% 666/android.hardware.graphics.composer@2.1-service: 6% user + 7.5% kernel / faults: 38 minor 10% 1534/system_server: 4.9% user + 5.3% kernel / faults: 16839 minor 181 major 3.3% 3033/com.asus.launcher: 2.7% user + 0.5% kernel / faults: 11367 minor 116 major 3.1% 3082/com.android.vending: 2.4% user + 0.7% kernel / faults: 5838 minor 27 major 2.9% 251/crtc_commit:111: 0% user + 2.9% kernel 2.3% 258/kgsl_worker_thr: 0% user + 2.3% kernel 1.9% 6751/kworker/u16:15: 0% user + 1.9% kernel 1.8% 4262/com.google.android.googlequicksearchbox:search: 1.6% user + 0.2% kernel / faults: 7234 minor 2 major 1.7% 9625/kworker/u16:10: 0% user + 1.7% kernel 1.5% 9644/kworker/u16:22: 0% user + 1.5% kernel 1.5% 9631/kworker/u16:13: 0% user + 1.5% kernel 1.3% 671/android.hardware.sensors@1.0-service: 0.6% user + 0.7% kernel / faults: 86 minor 0.2% 1027/media.codec: 0.1% user + 0% kernel / faults: 4454 minor 19 major 0.9% 562/logd: 0.5% user + 0.4% kernel / faults: 9 minor 5 major 0.9% 2274/com.asus.services: 0.4% user + 0.4% kernel / faults: 1543 minor 74 major 0.9% 2839/adbd: 0.2% user + 0.7% kernel / faults: 1538 minor 1 major 0.7% 2018/com.android.phone: 0.3% user + 0.4% kernel / faults: 1220 minor 69 major 0.6% 7780/com.asus.nextappcore: 0.4% user + 0.2% kernel / faults: 1712 minor 1039 major 0.6% 6755/kworker/u16:16: 0% user + 0.6% kernel 0.6% 9297/com.google.android.gm: 0.3% user + 0.2% kernel / faults: 1130 minor 3 major 0.6% 252/crtc_event:111: 0% user + 0.6% kernel 0.4% 2612/com.google.android.gms: 0.3% user + 0.1% kernel / faults: 316 minor 0.4% 9622/kworker/u16:5: 0% user + 0.4% kernel 0.4% 3175/com.lilithgame.hgame.gp.tw:lilith_sdk: 0.2% user + 0.1% kernel / faults: 1060 minor 0.3% 2455/com.google.android.gms.persistent: 0.2% user + 0.1% kernel / faults: 691 minor 0.3% 146/kswapd0: 0% user + 0.3% kernel 0.3% 563/servicemanager: 0.1% user + 0.2% kernel 0.3% 695/lmkd: 0% user + 0.3% kernel 0.3% 3141/com.facebook.katana: 0.3% user + 0% kernel / faults: 87 minor 0.3% 8407/kworker/1:6: 0% user + 0.3% kernel 0.3% 9925/kworker/0:6: 0% user + 0.3% kernel 0.3% 22551/com.android.chrome:sandboxed: 0% user + 0.2% kernel / faults: 1128 minor 273 major 0.3% 9714/kworker/3:0: 0% user + 0.3% kernel 0.2% 7/rcu_preempt: 0% user + 0.2% kernel 0% 1019/media.extractor: 0% user + 0% kernel / faults: 2514 minor 22 major 0.2% 3894/jp.naver.line.android: 0.2% user + 0% kernel / faults: 18 minor 0.2% 9977/kworker/2:0: 0% user + 0.2% kernel 0.2% 19548/com.facebook.orca:videoplayer: 0.1% user + 0.1% kernel / faults: 1 minor 0.2% 21131/kworker/u17:0: 0% user + 0.2% kernel 0.2% 10/rcuop/0: 0% user + 0.2% kernel 0.2% 102/system: 0% user + 0.2% kernel 0% 1831/com.google.android.apps.inputmethod.zhuyin: 0% user + 0% kernel / faults: 1024 minor 77 major 0.2% 29/rcuop/2: 0% user + 0.2% kernel 0.2% 2723/sugov:0: 0% user + 0.2% kernel 0% 4470/com.asus.deskclock:ui: 0% user + 0% kernel / faults: 216 minor 328 major 0.1% 1//init: 0.1% user + 0% kernel / faults: 157 minor 0.1% 665/android.hardware.graphics.allocator@2.0-service: 0% user + 0.1% kernel / faults: 7 minor 0% 1982/com.qualcomm.qti.telephonyservice: 0% user + 0% kernel / faults: 1128 minor 84 major 0% 2034/com.qualcomm.qtil.aptxui: 0% user + 0% kernel / faults: 1281 minor 303 major 0.1% 2944/com.android.nfc: 0.1% user + 0% kernel / faults: 1039 minor 84 major 0.1% 681/vendor.qti.hardware.perf@1.0-service: 0% user + 0.1% kernel / faults: 43 minor 0.1% 962/jbd2/dm-2-8: 0% user + 0.1% kernel 0.1% 1223/msm_irqbalance: 0% user + 0.1% kernel 0% 1998/org.ifaa.andr

ZahraHeydari commented 4 years ago

I fixed it by calling startForeground inside onCreate() for PlayerService (because of Android 8.0 behavior changes). Please let me know if still something is wrong.

a1573595 commented 4 years ago

It works well, thank you.