tags:

views:

39

answers:

1

hi.

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. 
                } 
A: 

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.

iPaulPro
every call of startActivity() generate new activity ? as i want existing activity's ListView and want to update, i didnt use startActivity().instead of it, i put BroadCastReceiver in my Activity.and now application is working fine. thank you very much !
Glad to help! BTW - startActivity() only generates a "new" activity in certain situations. For example, if you set launchMode="singleInstance", the existing activity will be brought to the front, and onNewIntent() will be fired. Please remember to accept this answer if it solved your problem.
iPaulPro