Search code examples
javaandroidandroid-notificationsandroid-roomandroid-viewmodel

How to get Data out of a Room-Database in a non-Activity. (in a JobIntentService for a notification)


I want to get a List from my Room-Database for a notification, where I use a BroadcastReceiver and a JobIntentService.

Because I don't have a context I can't obtain the ViewModel. So I need another way to get the data.

In this article I read something about a Singleton. But I don't know how to get the data now from the database with the Singleton.


Solution

  • I solved the issue like this: I saved the important data I need for the notification in Shared Preferences. In the BroadcastReceiver I can retrieve the data from the Shared Preferences and use it in the notification.