@Override public int onStartCommand(Intent intent, int flags, int startId) { // TODO Auto-generated method stub final AlarmManager am = (AlarmManager) getSystemService(Context.ALARM_SERVICE) ; long elapseTime = 60*1000l; Intent toWake = new Intent(this, PiggyService.class); final PendingIntent wakeupIntent = PendingIntent.getService(this, 0, toWake,0 ); am.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime()+elapseTime, wakeupIntent); return START_NOT_STICKY; }
START_NOT_STICKY表示要求的系统优先级要低,允许系统回归该组件,只是定时触发唤醒而已。
同理还有START_STICKY 表示要求系统不回收该组件(如听歌组件等,回收会影响用户体验的服务)
START_REDELIVER_INTENT表示如果该组件在执行中被系统回收,在重新调用时会复原传入的Intent对象确保中间数据不会丢失。