last day (15 days later) » 

03:15
-1
A: Android 9.0: Not allowed to start service: app is in background.. after onResume()

Er. Pratik ChatterjeeYou need to take foreground permission in android 9 pie and rest u can create foreground service using notification and it needs to be done within 5 seconds after starting the service for Oreo and above. @Override public void onCreate() { super.onCreate(); this.context = this; show...

The question relates to running a regular Service while the app is in the foreground. Your answer is about a Foreground Service running while the app is in the background.
I know u asked for background service but i would like to suggest you to switch to foreground services for music player app as per best practices. Once check the description of foreground app developer.android.com/guide/components/services
A foreground service is not required while the app is running in the foreground. Thanks for the suggestion, but unfortunately this doesn't resolve the question at hand.
Ya if app is in foreground then u dont need foreground services. but i saw that it was in background when u tried to start the service according to the logs cmp=another.music.player/com.simplecity.amp_library.playback‌​.MusicService }: app is in background uid UidRecord{6a4a9c6 u0a143 TPSL bg:+3m25s199ms idle change:cached procs:1 seq(1283,1283,1283)} at android.app.ContextImpl.startServiceCommon(ContextImpl.java:‌​1577) at android.app.ContextImpl.startService(ContextImpl.java:1532) at android.content.ContextWrapper.startService(ContextWrapper.j‌​ava:664) at android.content.ContextWrapper.startServi
See actually u are edditing the description regularly for what do u want. The solution was according to question u posted in begining. But your question got changed later
@tim i would really like to help you but i dnt have your source code to check and in my app it didnt crash android 9 when i created the with target version 28 by starting background service in onresume
Thanks Ed. The only change to the original question was for clarity. You can view the edits if you like. The description and problem statement has not changed at all. Appreciate your assistance, but unfortunately your answer does not resolve the issue. The 'app is in background' is exactly the problem here - why is Android reporting that the app is in the background, after onResume() is called? The answer is not 'because I didn't call startForeground()`' This is due to a platform bug by the looks of it. See issuetracker.google.com/issues/113122354
03:15
@TimMalseed welcome 🙂
Hi @Ed
Just wondering if we could chat about this issue?
So, just to be clear, the only edit I made to the question was changing wrappedContext to this, because it was confusing some readers.
In response to your comment:

>Ya if app is in foreground then u dont need foreground services. but i saw that it was in background when u tried to start the service according
This is exactly the problem. The app isn't in the background (because onResume() has been called), but the Android Platform thinks that the app is in the background.
So, unfortunately, starting the service in the foreground isn't a good solution to this problem. It might be a workaround, but the real issue is that Android thinks the app is backgrounded, even after the Activity is resumed.
Ok. Which devices you tested with? I am using pixel experiance rom and not facing this issue
I'm not really sure how that's relevant?
03:21
Just thought in case some oems customise the implementation so just asked
Also, sorry I've been referring to you as 'Ed'. My mistake! I have someone I regularly chat with called Ed, and I misread 'Er.;!
Can u send me small sample which i can import and test on my device?
Its ok.
Yeah, it could be custom OEM problems. But given that a Senior Software Engineer at Google commented and said 'we're seeing this issue in-house', I figure that it's probably happening on many different ROMs
But, no. I've reported this issue to Google:
https://issuetracker.google.com/issues/113122354

And it's assigned, so I'm not really worried about investigating further.
03:23
May be m lucky in that case that my app n device are not getting effected then 😊
I can't reproduce this on my devices either. But hundreds (maybe thousands now) of users can
So, I'd kindly request that you delete your answer, as

"You need to take foreground permission in android 9 pie and rest u can create foreground service "

Is not a solution to this problem.
Thanks. And again, I appreciate you taking your time to try to help :)
Welcome
By the way i would like to ask u two questions how to delete an answer as m seeing edit option but not delete. 2nd how to open a chat as m new here
sorry, delete option was not visible in the app but its visible in web.

last day (15 days later) »