I have to develop an application that gives a popup message at a certain time which is set by the user.
I will use the android AlarmManager, which starts a service, and that service will start the activity containing the popup interface with an OK button.
I want to pass data to that activity, how can this be done (otherwise i will have to query the database)?
- How to pass data from the activity to the service while setting the starting time using AlarmManager?
- How to later pass that data to the activity that is started by the service?
Also if a service starts an activity in my application (not the main activity), and database handler functions are in a separate class, is the database accessible?
When you pass a PendingIntent object to the AlarmManager.set method, you can put any extras you want in the Intent object wrapped in the pending intent. For example:
And then, as the service starts you receive the same intent object:
And you can do the same when starting the activity from your service:
In fact, if you don’t do anything special in your service but launching the activity, why won’t you just set an intent for the activity in your alarm?