Adding Notifications to Android App
<p>I want to implement notifications for my android application, but I don't know what class is best for the task.</p>

<p>I just read about <code>AlarmManager</code>, is this  class battery-friendly?</p>

<p>If it is, can anyone give me an example on how to set a notification for a future event (say, 2 or 3 days after I set it)?.</p>

<p>I have this source code as an example, it is supposed to notify me after 30 seconds with an alarm and a toast message, but doesn't work.</p>

<pre><code>package com.rNetworks.testAlarm;

import java.util.Calendar;

import android.app.Activity;
import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.Intent;
import android.os.Bundle;
import android.os.SystemClock;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;

public class AndroidTestAlarmActivity extends Activity {

    private PendingIntent mAlarmSender;


    private OnClickListener lstStart= new OnClickListener(){

        @Override
        public void onClick(View arg0) {
            //
            // We want the alarm to go off 30 seconds from now.
            long firstTime = SystemClock.elapsedRealtime();

            // Schedule the alarm!
            AlarmManager am = (AlarmManager)getSystemService(ALARM_SERVICE);
            am.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP,
                            firstTime, 30*1000, mAlarmSender);

            // Tell the user about what we did.
            Toast.makeText(AndroidTestAlarmActivity.this, "sdasdads",
                    Toast.LENGTH_LONG).show();

        }

    };

    private OnClickListener lstStop= new OnClickListener(){

        @Override
        public void onClick(View v) {
            AlarmManager alarmManager =(AlarmManager)getSystemService(ALARM_SERVICE);
            alarmManager.cancel(mAlarmSender);
            Toast.makeText(AndroidTestAlarmActivity.this, "Cancelando Alarma :(",Toast.LENGTH_SHORT).show();

        }
    };
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        Button btnStart=(Button)findViewById(R.id.btnStart);
        Button btnStop=(Button)findViewById(R.id.btnStop);
        mAlarmSender = PendingIntent.getService(AndroidTestAlarmActivity.this,
                0, new Intent(AndroidTestAlarmActivity.this, Alarm.class), 0);

        btnStart.setOnClickListener(lstStart);
        btnStop.setOnClickListener(lstStop);

    }




}
</code></pre>

<p>I want some like a ToDo List with Notifications :)</p>

<p>Thanks :)</p>
