Search code examples
androidandroid-studioservice

What would cause an service app to work on Android 8 but fail on Android 12?


I'm trying to learn how to use background services and have been watching videos, recreating working demos, etc to understand how it all works. I've now run two different demos that seem to work on Android 8 but fail on Android 12 (I try to run the app and i:t crashes immediately. I restart it again and it crashes and gives me the error ("Example" being the app name in this case):

"Clear Cache for Example? Example is closed because the app has a bug. Try clearing the app's cache first and then reopen the app"

Unfortunately, I don't really know what's breaking, so I'm not sure how to fix it . . . any idea what might be causing my problems? Here is one example that's clearly documented for reference:

https://erev0s.com/blog/run-android-service-background-reliably-every-n-seconds/

Any ideas what might be causing it? Any help you can give me would be greatly appreciated. Thanks!


Solution

  • If you are using any pending intents use the following as flags

    PendingIntent.FLAG_MUTABLE or PendingIntent.FLAG_IMMUTABLE

    in Android 12 or above. It might solve your issue