Hello Everyone,

I new to the SDK and have intermediate Java skills and I am having an issue
with adding an AlertDialog to a Receiver I have created. The application is
a basic alarm clock and I am using the following code as the receiving
class. I want to use an AlertDialog instead of Toast so that I can have a
snooze and an off button. It seems to be creating the AlertBox fine but when
I try to show it the program blows up. Below is the code I am trying to use,
any help is much appreciated!

Thanks,
Brad

public class RepeatingAlarm extends BroadcastReceiver {


 @Override

public void onReceive(Context context, Intent intent) {

try {

// Do something when alarm goes off

AlertDialog.Builder alertbox = new AlertDialog.Builder(context);

alertbox.setMessage("Its time to get up");

// add a neutral button to the alert box and assign a click listener

alertbox.setNeutralButton("Ok",

new DialogInterface.OnClickListener() {


 // click listener on the alert box

public void onClick(DialogInterface arg0, int arg1) {

// the button was clicked do something


 }

});


 alertbox.show();


 } catch (Exception e) {

Log.e("AlarmClock.java", "ERROR: ", e);

}


 MediaPlayer mp = MediaPlayer.create(context, R.raw.duck);

mp.start();


 }


}

-- 
You received this message because you are subscribed to the Google
Groups "Android Beginners" group.

NEW! Try asking and tagging your question on Stack Overflow at
http://stackoverflow.com/questions/tagged/android

To unsubscribe from this group, send email to
android-beginners+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-beginners?hl=en

Reply via email to