Develop Alarm Application

I’d like develop an Alarm Application.
The application should work like this:

  • launch it
  • the activity show me the time
  • I can set the alarm
  • I can close the application
  • when the alarm time comes , it starts an activity (even if the device is locked)

I have tried to adapt this sample but I cannot launch an activity when the alarm time comes.

  • Android: how to remove an item from a listView and arrayAdapter
  • Filter LogCat to get only the messages from My Application in Android?
  • How to write drivers for Android?
  • Is there an AppCompat equivalent of Widget.Material.Spinner.Underlined?
  • Hiding Toolbar on scroll with recyclerview inside fragment
  • Search all the occurrences of a string in the entire project in Android Studio
  • I use this code to setup the alarm (for test I have inserted this code on an onCreate method of activity):

    Intent intent = new Intent(this, OnAlarmReceiver.class);
    PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, intent, 0);
    Calendar cal = Calendar.getInstance();
    cal.add(Calendar.SECOND, 10);
    AlarmManager alarm = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
    alarm.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, cal.getTimeInMillis(),

    this is the OnAlarmReceiver class:

    public class OnAlarmReceiver extends BroadcastReceiver {
        public void onReceive(Context context, Intent intent) {
            Log.i(ClockActivity.LOG_TAG, "OnAlarmReceiver::onReceive");
            WakefulIntentService.sendWakefulWork(context, AlarmService.class);

    this is the service class:

    public class AlarmService extends WakefulIntentService {
        public AlarmService(String name) {
        protected void doWakefulWork(Intent intent) {
            Log.i(ClockActivity.LOG_TAG, "AlarmService::doWakefulWork");
            Intent newIntent = new Intent(getApplicationContext(), ClockActivity.class);

    this is the portion of Manifest where are setup the service and the receiver:

    <receiver android:name=".OnAlarmReceiver"></receiver>
    <service android:name=".AlarmService"></service>

    the doWakefulWork method is never called!

  • Using Application context everywhere?
  • How to move and rename a project in android studio?
  • android how an EditText work as AutoComplete
  • why should i use android service instead of java thread
  • Stopping an Android app from console
  • change edittext cursor color
  • 4 Solutions collect form web for “Develop Alarm Application”

    I have made this application:

    import pack.breceiver.MyBroadcastReceiver;
    import android.content.Intent;
    import android.os.Bundle;
    import android.view.View;
    import android.widget.EditText;
    import android.widget.Toast;
    import android.os.Bundle;
    public class AlarmActivity extends Activity {
        /** Called when the activity is first created. */
        public void onCreate(Bundle savedInstanceState) {
        public void startAlert(View view) {
            EditText text = (EditText) findViewById(;
            int i = Integer.parseInt(text.getText().toString());
            Intent intent = new Intent(this, MyBroadcastReceiver.class);
            PendingIntent pendingIntent = PendingIntent.getBroadcast(
                    this.getApplicationContext(), 234324243, intent, 0);
            AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
            alarmManager.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis()
                    + (i * 1000), pendingIntent);
            Toast.makeText(this, "Alarm set in " + i + " seconds",

    package pack.breceiver;
    import android.content.BroadcastReceiver;
    import android.content.Context;
    import android.content.Intent;
    import android.os.Vibrator;
    import android.widget.Toast;
    public class MyBroadcastReceiver extends BroadcastReceiver  {
        public void onReceive(Context context, Intent intent) {
            Toast.makeText(context, "Don't panik but your time is up!!!!",
            /*// Vibrate the mobile phone
            Vibrator vibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
            vibrator.vibrate(2000);  */

    check this out :


        AlarmCal.getTimeInMillis(), AlarmManager.INTERVAL_FIFTEEN_MINUTES,

    I had a similar problem and I resolved removing the receiver from manifest and set in my code registering him with registerReceiver.

    Do you get an instantiation exception maybe ?

    You should have a public no arg constructor in your service :

    public class AlarmService extends WakefulIntentService {
        public AlarmService() {
        // etc
    Android Babe is a Google Android Fan, All about Android Phones, Android Wear, Android Dev and Android Games Apps and so on.