7. §±§â§Ú§Þ§Ö§â
public class SampleService extends Service {?
Handler mHandler;?
?
@Override?
public void onCreate() {?
super.onCreate();?
mHandler = new Handler();?
}?
?
@Override?
public void onDestroy() {?
super.onDestroy();?
mHandler = null;?
}?
}
8. §±§â§Ú§Þ§Ö§â
public class SampleService extends Service {?
¡?
?
@Override?
public int onStartCommand(@Nullable Intent intent,
int ?ags,
int startId) {?
mHandler.postDelayed(() -> stopSelf(startId), showToast());?
return START_STICKY;?
}?
¡
}
30. §±§â§Ú§Þ§Ö§â
public class TaskSampleService extends GcmTaskService {?
?
@GcmTaskResultDef?
@Override?
public int onRunTask(TaskParams taskParams) {?
if (SAMPLE_JOB_TAG.equals(taskParams.getTag())) {?
// Do long work. Execute on background thread by default.?
}?
return GcmNetworkManager.RESULT_SUCCESS;?
}?
}
32. §±§â§Ú§Þ§Ö§â
public class GcmNetworkManagerService extends GcmTaskService {?
?
@Override?
public void onInitializeTasks() {?
// Restore tasks after application package updated.
// Not called on ?rst start.
}?
}