@Override public IBinder onBind(Intent intent) { // TODO: Return the communication channel to the service. thrownew UnsupportedOperationException("Not yet implemented"); }
@Override publicintonStartCommand(Intent intent, int flags, int startId) { new Thread(new Runnable() { @Override publicvoidrun() { Log.d("LongRunningService", "excuted" + new Date().toString()); } }).start(); AlarmManager manager = (AlarmManager) getSystemService(Context.ALARM_SERVICE); int anHour = 60*60*1000; long trigerAtTime = SystemClock.elapsedRealtime()+anHour; Intent alarmIntent = new Intent(this,AlarmReceive.class); PendingIntent pendingIntent = PendingIntent.getBroadcast(this,0,alarmIntent,0); manager.set(AlarmManager.ELAPSED_REALTIME_WAKEUP,trigerAtTime,pendingIntent); returnsuper.onStartCommand(intent, flags, startId); } }
receiver
publicvoidonReceive(Context context, Intent intent) { // TODO: This method is called when the BroadcastReceiver is receiving // an Intent broadcast. Intent i = new Intent(context,LongRunningService.class); context.startService(i); } }