Reputation: 71
Im developping alarm application.
I'm using listview on activity to reserve alarm. after application finish BroadcastReceiver.onReceive() method, I want to remove check of list.
But i dont know how to access to activity. anybody knows?
The following is my code:
public class Activity_001 extends ListActivity {
Intent intent = new Intent(this, ReceiverGenerateAlarm.class);
intent.setAction(Conf.GenerateAlarm);
intent.putExtra(cal,timerList.get(0).getCal().getTimeInMillis())
PendingIntent sender = PendingIntent.getBroadcast(this, 0, intent,
0);
AlarmManager am = (AlarmManager)
(this.getSystemService(ALARM_SERVICE));
am.set(AlarmManager.RTC_WAKEUP,
timerList.get(0).getCal().getTimeInMillis(), sender);
}
.
public class ReceiverGenerateAlarm extends BroadcastReceiver {
@Override
public void onReceive(Context context,Intent intent) {
String action = intent.getAction();
if(action.equals(Conf.GenerateAlarm)) {
Bundle bundle=intent.getExtras();
long cal = bundle.getLongArray("cal");
Calendar c = Calendar.getInstance();
c.setTimeInMillis(cal);
MediaPlayer_inherit_Class tm = new MediaPlayer_inherit_Class(cal);
tm.play();
//in here, wanna access alarm reservation list and remove check of list. as application has executed.
//set next alarm, if needed.
}
Upvotes: 0
Views: 3277
Reputation: 25584
If I understand you correctly, you should be using a SQLite db to store your "alarm reservations". If this is true, simply update your db entries in your onReceive()
. When the Activity
is restored, it should check for changes to the alarm db table and update the UI accordingly.
One alternative is to call startActivity()
from your onReceive()
with bundled extras. Possibly pass a row id or time-stamp to query with Intent.putExtra()
.
Another is to put the BroadcastReceiver
in your Activity
class.
Hope that helps.
Upvotes: 1