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.

  • Paho MQTT Android service wake up activity
  • ANDROID: How to gain root access in an Android application?
  • Is android:exported=“true” really necessary for an authentication service?
  • Bad notification posted from package Couldn't expand RemoteViews
  • Android peer not authenticated
  • Android EditText background text
  • 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!

    Related posts:

    How to hide status bar in Android
    Android build error due to incorrect java version
    Installing PhoneGap, error executing command &#039;ant&#039;
    The specified child already has a parent. You must call removeView() on the child&#039;s parent ...
    Phonegap input type password field focus
    Bouncy Castle Keystore (BKS) : Wrong version of key store
  • “Time Since/Ago” Library for Android/Java
  • Disabling Android menu button in PhoneGap Build
  • Android media player returns IllegalStateException
  • Send text through Bluetooth from Java Server to Android Client
  • Jacoco Code Coverage in android studio
  • Adding items to ListView, maintaining scroll position and NOT seeing a scroll jump
  • 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.