Reputation: 831
I have an alarm
(repeatingalarm) and BroadcastReceiver
to handle it. the alarm is set in my activity
with pending intent referring to BroadcastReceiver
class. I have a sqlite
database in my activity. i want to update my sqlite database in my alarm so i need sqlite object from my activity. it is needed for my asynctask
too which is executed in my alarm too. how can i do that?
in short terms, i want to pass my activity object to my broadcast constructor so i can use my sqlite instance.
EDIT: I noticed that if i define BroadcastReciever
inside my activity, i can refer to it as simple as MyActivity.this. is there any other way rather than this.
Upvotes: 0
Views: 78
Reputation: 5711
you can not do too much work in 'broadcastreceiver' .
Intend you must create one service class to do this and call service from 'broadcastreceiver' . and then write your DataBase code in Service
.
In Service you can create 'sqlite
' DataBase
object through getApplicationConext()
.
Also within Service must create Seperate Thread for your work or use AsyncTask
to do your DataBase Operations.
Upvotes: 1