 Gazdaman I did a trackday!!!

Joined: 12 Aug 2004 Karma :    
|
 Posted: 16:09 - 03 Feb 2011 Post subject: Android coders? |
 |
|
So I want to write an app that is based around an alarm, so I've started writing the basics, and I can't see why this code won't work.
It sets an alarm through AlarmManager.set(), and sets it for 5 seconds after it's set.
It pops up the Toast to confirm the alarm's been set. But it doesn't appear to run the method that is the alarm 'going off'.
Anyone spot any errors?
| Code: |
package com.example.AlarmTest;
import android.app.Activity;
import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.widget.Toast;
public class AlarmTest extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
Intent intent = new Intent(this, OnetimeAlarmReceiver.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, intent, 0);
alarmManager.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + (5 * 1000), pendingIntent);
Toast.makeText(this, "Alarm set", Toast.LENGTH_LONG).show();
}
public class OnetimeAlarmReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
Toast.makeText(context, "Alarm worked.", Toast.LENGTH_LONG).show();
}
}
}
|
Karma for any help!
Gaz |
|
 Frost World Chat Champion

Joined: 26 May 2004 Karma :  
|
|