In JobService open SQLite database with Context

418 Views Asked by At

In my application I write jobs into a queue in a SQLite table. With a JobService I would like to process this queue.

I'm currently struggling to access the database from inside the the JobService as I require the Context. Both getBaseContext() and getApplicationContext() leave me with

Attempt to invoke virtual method 'android.content.Context android.content.Context.getApplicationContext()' on a null object reference

As I seem to gather from https://developer.android.com/reference/android/app/job/JobService.html JobService seems to inherit from Context but it doesn't seem sufficient to just use this as Context.

I'm using a helper class extending SQLiteOpenHelper with the database.

Thank you for your time.

€: I was too hasty and tried to use this as context in my constructor. As soon as I moved my initialization code to a different part it works as intended.

0

There are 0 best solutions below