title: Setting Multiple alarms on my alarm application
body: <p>In my application I am able to play alarm tone on specified time using timepicker..But when i press the set alarm button again it replaces the previous alarm.. Could anyone help to store multiple alarms...and also please tell where the time for ringing the alarm is stored in application?</p>
  
  <p>Alarmreceiver.java</p>
  
  <pre><code>    package com.example.alaram;
  
  import java.io.IOException;
  
  import android.app.Activity;
  import android.content.Context;
  import android.media.AudioManager;
  import android.media.MediaPlayer;
  import android.media.RingtoneManager;
  import android.net.Uri;
  import android.os.Bundle;
  import android.os.PowerManager;
  import android.os.PowerManager.WakeLock;
  import android.util.Log;
  import android.view.View;
  import android.view.Window;
  import android.view.WindowManager;
  import android.widget.Button;
  
  
  
  
              public class AlarmReceiver extends Activity{
          private MediaPlayer mPlayer;
          private WakeLock mWakeLock;
              Button stopalarm;
  
          @SuppressWarnings("deprecation")
          public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
  
      PowerManager pm=(PowerManager) getSystemService(Context.POWER_SERVICE);
      mWakeLock =pm.newWakeLock(PowerManager.FULL_WAKE_LOCK, "my wakelock");
      mWakeLock.acquire();
      this.requestWindowFeature(Window.FEATURE_NO_TITLE);
      this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN | 
              WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED | 
              WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON, 
              WindowManager.LayoutParams.FLAG_FULLSCREEN |
              WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED | 
              WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON );
  
      setContentView(R.layout.alarmreceiver);
  
      //Stop the alarm music
      stopalarm=(Button) findViewById(R.id.btnStopoAlarm);
      stopalarm.setOnClickListener(new View.OnClickListener() {
  
          @Override
          public void onClick(View v) {
              // TODO Auto-generated method stub
               mPlayer.stop();
                  finish();
                  return;
          }
      });
      PlaySound(this,getAlarmUri());
  }
  
  
  private void PlaySound(Context context,Uri alert){
      mPlayer=new MediaPlayer();
      try{
          mPlayer.setDataSource(context,alert);
          final AudioManager am=(AudioManager) getSystemService(Context.AUDIO_SERVICE);
          if(am.getStreamVolume(AudioManager.STREAM_ALARM)!=0);
          {
              mPlayer.setAudioStreamType(AudioManager.STREAM_ALARM);
              mPlayer.prepare();
              mPlayer.start();
          }
  
      }catch(IOException e)
      {
      Log.i("AlaramReciever", "no audio file");
      }
  }
  
   //Get an alarm sound.  If none set, try notification, Otherwise, ringtone.
  private Uri getAlarmUri()
  {
      Uri alert= RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
      if(alert==null)
      {
          alert= RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
          if(alert==null)
          {
              alert=RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE);
          }
      }
      return alert;
  }
  
  protected void onStop(){
      super.onStop();
       mWakeLock.release();
  
  }
  </code></pre>
  
  <p>}</p>
  
  <p>SetAlarm.java</p>
  
  <pre><code>package com.example.alaram;
  
  import java.util.Calendar;
  import android.app.Activity;
  import android.app.AlarmManager;
  import android.app.PendingIntent;
  import android.content.Context;
  import android.content.Intent;
  import android.os.Bundle;
  import android.view.View;
  import android.widget.Button;
  import android.widget.TimePicker;
  import android.widget.Toast;
  
  public class SetAlarm extends Activity {
  
  TimePicker timePicker;
  Button ok;
  int hrs,min;
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.setalarm);
  
  //Operation of Ok button or Setting Alaram Time
  ok=(Button) findViewById(R.id.btnOk);
  ok.setOnClickListener(new View.OnClickListener() {
  
      @Override
      public void onClick(View v) {
          // TODO Auto-generated method stub
  
          Intent intent=new Intent(SetAlarm.this,AlarmReceiver.class);
          PendingIntent pi=PendingIntent.getActivity(SetAlarm.this, 2,    intent,PendingIntent.FLAG_CANCEL_CURRENT);
          AlarmManager alm=(AlarmManager) getSystemService(Context.ALARM_SERVICE);
  
          timePicker=(TimePicker) findViewById(R.id.timePicker1);
          hrs=timePicker.getCurrentHour();
          min=timePicker.getCurrentMinute();
          Calendar calendar=Calendar.getInstance();
          calendar.set(Calendar.HOUR_OF_DAY,hrs);
          calendar.set(Calendar.MINUTE, min);
          calendar.set(Calendar.SECOND, 0);
  
          alm.set(AlarmManager.RTC_WAKEUP,calendar.getTimeInMillis(), pi);
          Toast.makeText(getBaseContext(), "Alaram is Set",Toast.LENGTH_SHORT).show();
  
          finish();   
          }
  
      });
  
  }   
  </code></pre>
  
  <p>}</p>