Reputation: 1051
i'm doing an android scheduled application , i use AlarmManager , but my alarm is not working , here are my code :
MyActivity :
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.HOUR, 1);
calendar.set(Calendar.SECOND, 44);
calendar.set(Calendar.AM_PM, Calendar.PM);
pendingIntent = PendingIntent.getBroadcast(this, 0, new Intent(this, MyBroadCastRcv.class), 0);
getApplicationContext();
AlarmManager alarmMngr = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
alarmMngr.set(AlarmManager.RTC, calendar.getTimeInMillis(), pendingIntent);
MyBroadCastRcv class:
public void onReceive(Context context, Intent intent)
{
Intent serviceLauncher = new Intent(context, TimerService.class);
context.startService(serviceLauncher);
}
my Service :
public int onStartCommand(Intent intent, int flags, int startId)
{
super.onCreate();
MediaPlayer player = MediaPlayer.create(this, Uri.parse("file:///mnt/sdcard/sherif/001.mp3"));
return super.onStartCommand(intent, flags, startId);
}
public void onStart(Intent intent, int startId)
{
System.out.println("In onStart Service");
super.onStart(intent, startId);
player.start();
}
am i missing something ?
Upvotes: 0
Views: 386
Reputation: 95636
Well, you definitely DO NOT want to call super.onCreate()
in onStartCommand()
. Remove that.
Also, your onStart()
will never be called. This method is deprecated. You need to put all the code in onStartCommand()
.
Upvotes: 1