My application receives an intent from a service which then pops up a notification. This intent has an object id from which I want to retrieve the whole object from my database so that I can set the notification title and subtitle. However, I need to pass in a context to my dbManager, and I have been receiving errors no matter which context I try.
The code is as follows:
public class ReceiveTransitionsIntentService extends IntentService {
private DBManager dbManager;
public ReceiveTransitionsIntentService() {
super("ReceiveTransitionsIntentService");
}
protected void onHandleIntent(Intent intent) {
//somewhere
sendNotification(..);
}
private void sendNotification(String transitionType, String ids) {
Intent notificationIntent =
new Intent(getApplicationContext(),MainActivity.class);
...
//have tried with getbaseContext() and this, still failures
dbManager = new DBManager(getApplicationContext());
...
}
}
Does anyone have any ideas on what I could do?
These are the errors:
new DBManager(this) -> java.lang.ClassCastException: .ReceiveTransitionsIntentService cannot be cast to android.app.Activity
new DBManager(getApplicationContext) -> java.lang.ClassCastException: android.app.Application cannot be cast to android.app.Activity
new DBManager(getBaseContext) -> java.lang.ClassCastException: android.app.Contextimpl cannot be cast to android.app.activity