Hi Megha!

I'm having a similar problem.  I want to be able to create a
notification and schedule an alarm from a BroadcastReceiver class.  Do
I have to make my BroadcastReceiver an inner class of an
Activity or is it just using a regular class that extends
BroadcastReceiver? Is it possible to launch other intents from a
BroadcastReceiver to trigger logic in an activity?


On Oct 21, 2:48 am, "Megha Joshi" <[EMAIL PROTECTED]> wrote:
> One of the options is to make your BroadcastReceiver an inner class of your
> Activity. It also makes sense to make BroadCasterReceiver as  Activity's
> inner class if its just going to update your Activity's UI.
>
> 2008/10/20 Abraham <[EMAIL PROTECTED]>
>
>
>
> > HI ,
>
> > I'm trying the understand how an application can receive intent in
> > BroadcastReceiver & how it can inform the Activity abt the information
> > received in the intent.
>
> > For this purpose I have created an activity which has a TextView. In
> > OnCreate of the Activity I'm using AlarmManager to start sending
> > intents every 10 sec to broadcast receiver of my application. On
> > receiving this intent I would like to update the text view with the
> > current time.
>
> > From the documention I understand that we need to be using the
> > NotificationManager instead of trying to directly updating the UI.
>
> > Can some one pls let me know how I can achieve this.
>
> > Code snippets:
> > public class myFaves extends Activity
> > {
> > public void onCreate(Bundle savedInstanceState)
> >    {
> >        super.onCreate(savedInstanceState);
> >        setContentView(R.layout.main);
> >        mCurrentTime = (TextView) findViewById(R.id.curtime_label);
> >       startUpdatingCurrentTime();
> >    }
>
> > protected void onPause()
> >    {
> >        super.onPause();
> >        cancelUpdatingCurrentTime();
> >    }
>
> > private void startUpdatingCurrentTime()
> > {
> >    Intent intent = new Intent(MyTimer.this, MyTimerReceiver.class);
> >    PendingIntent sender = PendingIntent.getBroadcast(MyTimer.this, 0,
> > intent, 0);
>
> >     // We want the alarm to go off every second from now.
> >     long firstTime = SystemClock.elapsedRealtime();
> >     firstTime += 10000;
>
> >     // Schedule the alarm!
> >     AlarmManager am = (AlarmManager)getSystemService(ALARM_SERVICE);
> >     am.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, firstTime,
> > 10000, sender);
>
> >     Calendar calendar = Calendar.getInstance();
> >     calendar.setTimeInMillis(System.currentTimeMillis());
> >     mCurrentTime.setText( calendar.getTime().toString());
> > }
>
> > public void cancelUpdatingCurrentTime()
> > {
> >    Intent intent = new Intent(MyTimer.this, MyTimerReceiver.class);
> >    PendingIntent sender = PendingIntent.getBroadcast(MyTimer.this, 0,
> > intent, 0);
>
> >    // And cancel the alarm.
> >    AlarmManager am = (AlarmManager)getSystemService(ALARM_SERVICE);
> >    am.cancel(sender);
> > }
> > }
>
> > public class MyTimerReceiver extends BroadcastReceiver
> > {
> >        protected static final String LOG_TAG = "MyTimer";
>
> >       [EMAIL PROTECTED]
> >        public void onReceive(Context context, Intent intent)
> >        {
> >                Log.d(LOG_TAG, "onReceive");
> >                                // How do I update the TextView with
> > current time in my activity?
> >        }
>
> > }

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to