This is my code:
public class Alarm extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Intent intent = new Intent(this, AlarmReceiver.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0,
intent, PendingIntent.FLAG_ONE_SHOT);
AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
alarmManager.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + (10 * 1000), pendingIntent);
Toast.makeText(this, "Alarm set", Toast.LENGTH_LONG).show();
}
}
and
public final class AlarmReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
Toast.makeText(context, "Alarm worked.", Toast.LENGTH_LONG).show();
}
}
By the above code i am able to get the Toast. Instead of Toast I want the Dialog to be appear after the alarm is set. Also I want to play the sound.
Any one help me please?
You cannot display a
Dialogfrom aBroadcastReceiverorService. You will be better served using anActivity(perhaps one usingTheme.Dialog) and callingstartActivity().Bear in mind, though, that users tend to really dislike it when background stuff pops up activities unannounced. For some apps — alarm clocks, VOIP clients, etc. — the user may be OK with it.