Hello all,

I'm building an application that does several different things. My
activities are represented as tabs across the top of the screen and
one of the activies is an alarm clock function. I'm using an activity
instead of a broadcast service to handle what happens when my alarm
goes off and everything is functioning well so far, I just have a
problem with the display.

When the alarm goes off, the activity that pops up covers all of the
tabs (which basically serve as a menu to the other activities) for the
application. I've seen some examples that use intent flags and an
activitygroup in order to keep a new activity under the tabs, but that
code will not work in this situation, at least not as I understand it.

Does anyone know of a way to keep the tabs on top once you land on the
activity that handles the alarm going off?

The reason I'm using an activity instead of a broadcast service is
because the alarm has to be able to play an online stream of audio
when it goes off. I tried to use the broadcast service and it did what
I wanted it to, except that the only way to turn off the stream once
you stop the alarm was to make a notification pop up...I feel this
would be confusing and that people would be more comfortable with a
button that tells them to stop the alarm.

Perhaps I'm going about this the wrong way but if anyone could help I
would really appreciate it.

Below is the code I used to set up the alarm manager:

//set up the intent for the alarm manager
alarmIntent = new Intent(v.getContext(), AlarmReceiver.class);
alarmIntent.putExtra("stream", "http://mp3.wusf.usf.edu:8000/";);

//set the pending intent to the intent we just created above
mAlarmSender = PendingIntent.getActivity(v.getContext(), 0,
alarmIntent, 0);

//Set up the alarm manager, using a hard-coded alarm time for now
AlarmManager alarmManager = (AlarmManager)
getSystemService(ALARM_SERVICE);
alarmManager.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() +
(5 * 1000), mAlarmSender);

And below is the AlarmReceiver class:

public class AlarmReceiver extends Activity {
        private Button stopAlarm;
        private MediaPlayer mediaPlayer;
        private Intent receivedIntent;
        private String streamURL;

        @Override
        public void onCreate(Bundle savedInstanceState)
        {
                super.onCreate(savedInstanceState);
                setContentView(R.layout.alarm_receiver);

                //capture the button
                stopAlarm = (Button) findViewById(R.id.stopAlarm);

                //get the extras that were sent
                receivedIntent = getIntent();
                streamURL = receivedIntent.getStringExtra("stream");

                //set up and start the mediaPlayer
                mediaPlayer = new MediaPlayer();
                try
                {
                        mediaPlayer.setDataSource(streamURL);
                        mediaPlayer.prepare();
                        mediaPlayer.start();
                }
                catch (Exception e)
                {
                                                  //exit as quickly as
possible
                        throw new RuntimeException(e);
                }

                //On click listener for the stop button
                stopAlarm.setOnClickListener(new OnClickListener () {
                        public void onClick(View v) {
                                //stop the media player
                                mediaPlayer.stop();
                                //TO DO: switch back to the alarm activity
                        }
                });

        }

        //release the resources for the media player when the activity is
destroyed
        @Override
        protected void onDestroy() {
                super.onDestroy();
                if(mediaPlayer != null)
                {
                        mediaPlayer.release();
                        mediaPlayer = null;
                }
        }
}

Thanks,
DanielleM

-- 
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