本文整理汇总了Java中android.app.Service.START_REDELIVER_INTENT属性的典型用法代码示例。如果您正苦于以下问题:Java Service.START_REDELIVER_INTENT属性的具体用法?Java Service.START_REDELIVER_INTENT怎么用?Java Service.START_REDELIVER_INTENT使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类android.app.Service
的用法示例。
在下文中一共展示了Service.START_REDELIVER_INTENT属性的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onStartCommand
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
if (BuildConfig.LOG_DEBUG) LogUtils.d(TAG, intent);
boolean isTriggeredAutomatically = isTriggeredAutomatically(intent);
if (intent != null && AppIntent.ACTION_SYNC_START.equals(intent.getAction())) {
if (!isRunning()) {
start(isTriggeredAutomatically);
}
} else if (intent != null && AppIntent.ACTION_SYNC_STOP.equals(intent.getAction())) {
if (isRunning()) {
stop();
}
} else {
if (isRunning()) {
stop();
} else {
start(isTriggeredAutomatically);
}
}
return Service.START_REDELIVER_INTENT;
}
示例2: onStartCommand
/**
* Executes an explicit command.
*
* This is the entry point for arbitrary commands that are executed upon reception of certain
* events that should be executed on the context of this service. The supported commands are:
* - Check last update time and possibly schedule an update of the data for later.
* This is triggered every day, upon reception of the DATE_CHANGED_INTENT_ACTION broadcast.
* - Update data NOW.
* This is normally received upon trigger of the scheduled update.
* - Handle a finished download.
* This executes the actions that must be taken after a file (metadata or dictionary data
* has been downloaded (or failed to download).
* The commands that can be spun an another thread will be executed serially, in order, on
* a worker thread that is created on demand and terminates after a short while if there isn't
* any work left to do.
*/
@Override
public synchronized int onStartCommand(final Intent intent, final int flags,
final int startId) {
final DictionaryService self = this;
if (SHOW_DOWNLOAD_TOAST_INTENT_ACTION.equals(intent.getAction())) {
final String localeString = intent.getStringExtra(LOCALE_INTENT_ARGUMENT);
if (localeString == null) {
Log.e(TAG, "Received " + intent.getAction() + " without locale; skipped");
} else {
// This is a UI action, it can't be run in another thread
showStartDownloadingToast(
this, LocaleUtils.constructLocaleFromString(localeString));
}
} else {
// If it's a command that does not require UI, arrange for the work to be done on a
// separate thread, so that we can return right away. The executor will spawn a thread
// if necessary, or reuse a thread that has become idle as appropriate.
// DATE_CHANGED or UPDATE_NOW are examples of commands that can be done on another
// thread.
mExecutor.submit(new Runnable() {
@Override
public void run() {
dispatchBroadcast(self, intent);
// Since calls to onStartCommand are serialized, the submissions to the executor
// are serialized. That means we are guaranteed to call the stopSelfResult()
// in the same order that we got them, so we don't need to take care of the
// order.
stopSelfResult(startId);
}
});
}
return Service.START_REDELIVER_INTENT;
}