'How to access Activity context in the Service class in android

I have an android app, where i am starting a service from an activity. I want to access the activity context from the service class and not the application context to perform some action. How can i achieve this



Solution 1:[1]

While inflating the layout, the context being a Service context and not the activity context, i am getting binary xml exception "You need to use a Theme.AppCompat theme (or descendant)" . What is the way to get around this

Eliminate everything from the layout that requires Theme.AppCompat and stick to framework widgets. AFAIK Jetpack Compose can also be used here, instead of layout resources, though it requires some additional setup.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 CommonsWare