Alarm in android
<p>I am using the following code for alarm, it will alert after 10 secs. Its works fine in emulator but in real device its forcely closing..can you guide me in correct way..
this is my actvity..</p>

<pre><code>      public class Alarm1 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,001000,intent,0);


AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
alarmManager.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + (5 * 1000), pendingIntent);
Toast.makeText(this,"Alarm set", Toast.LENGTH_LONG).show();
</code></pre>

<p>}
}`
This is receiver class</p>

<pre><code>public class AlarmReceiver extends BroadcastReceiver {

@Override
public void onReceive(Context context, Intent intent) {
    Toast.makeText(context, "Alarm worked", Toast.LENGTH_LONG).show();
    try{

        Intent back = new Intent(context,Alarm.class);
        back.addFlags(Intent.FLAG_FROM_BACKGROUND);
        back.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        back.setAction("android.intent.action.MAIN");
        back.addCategory("android.intent.category.LAUNCHER");
        context.startActivity(back);
    }
    catch(Exception e){}

}
</code></pre>

<p>}</p>

<p>This is to play Ringtone for alarm.</p>

<pre><code>public class Alarm extends Activity {
private MediaPlayer mp; /** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.alarm);
    mp = MediaPlayer.create(this, R.raw.up);
    mp.start();

    Button start = (Button) findViewById(R.id.Button01);
    start.setOnClickListener(vvvvv);
}

private OnClickListener vvvvv = new OnClickListener() {
    public void onClick(View v) {

        mp.stop();
        finish();
    }
};
</code></pre>

<p>}</p>

<p>This is working fine in emulator but not on real device..i used permissions also..
I am using Samsung Galaxy 1.6.
Thanks in advance..</p>
