本文整理匯總了Java中android.app.Activity.startService方法的典型用法代碼示例。如果您正苦於以下問題:Java Activity.startService方法的具體用法?Java Activity.startService怎麽用?Java Activity.startService使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.app.Activity
的用法示例。
在下文中一共展示了Activity.startService方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: setupLocationService
import android.app.Activity; //導入方法依賴的package包/類
@NeedsPermission(Manifest.permission.ACCESS_FINE_LOCATION)
// Must be public to use PermissionsDispatcher
public void setupLocationService() {
final String tag="setupLocationService - ";
if (isAdded()) {
final Activity activity=getActivity();
if (activity!=null){
locationServiceConnection = new LocationServiceConnection((OwnLocationReceivedListener) this);
Intent serviceIntent = new Intent(activity,TrackService.class);
activity.startService(serviceIntent);
activity.bindService(new Intent(activity,TrackService.class), locationServiceConnection, Context.BIND_AUTO_CREATE);
} else {
Log.e(TAG,tag+"Activity is null.");
}
}
}
示例2: requestPushToken
import android.app.Activity; //導入方法依賴的package包/類
void requestPushToken(Activity activity){
if (activity!=null) {
Intent service = new Intent(activity, RegistrationIntentService.class);
service.putExtra(RegistrationIntentService.TOKEN, "token");
activity.startService(service);
IntentFilter intentFilter = new IntentFilter(RegistrationIntentService.ACTION_TOKEN);
intentFilter.addCategory(Intent.CATEGORY_DEFAULT);
activity.registerReceiver(tokenBroadcastReceiver, intentFilter);
//send back first
sendBroadCast();
}
else{
}
}
示例3: updateFavorites
import android.app.Activity; //導入方法依賴的package包/類
private void updateFavorites() {
if (mAdapter != null) {
Activity activity = getActivity();
if (activity != null) {
for (int i = 0; i < mAdapter.getItemCount(); i++) {
if (TextUtils.isEmpty(mAdapter.getItem(i).getUrl()))
continue;
if (mAdapter.getItem(i).getStatus() == 1)
continue;
Intent msgIntent = new Intent(activity,
ManualAnimeUpdaterService.class);
msgIntent.putExtra(Constants.ANIME_URL, mAdapter.getItem(i).getUrl());
activity.startService(msgIntent);
}
}
}
}
示例4: startService
import android.app.Activity; //導入方法依賴的package包/類
/**
* Bind the activity to a background service and put them into foreground
* state.
*/
private void startService() {
Activity context = cordova.getActivity();
if (isDisabled || isBind)
return;
Intent intent = new Intent(
context, ForegroundService.class);
try {
context.bindService(intent,
connection, Context.BIND_AUTO_CREATE);
fireEvent(Event.ACTIVATE, null);
context.startService(intent);
} catch (Exception e) {
fireEvent(Event.FAILURE, String.format("'%s'", e.getMessage()));
}
isBind = true;
}
示例5: LoadLeDongLiSteps
import android.app.Activity; //導入方法依賴的package包/類
public static void LoadLeDongLiSteps(Activity activity, CallBack callBack) {
if (activity != null && callBack != null) {
resultCallBack = callBack;
Intent intent = new Intent("cn.ledongli.ldl.ledongliservice");
intent.putExtra(PACKAGE_NAME, activity.getPackageName());
intent.putExtra(QUERY_STRING, "step");
Intent wrapperedIntent = createExplicitFromImplicitIntent(activity, intent);
if (wrapperedIntent == null) {
resultCallBack.onFailed("樂動力不在呀,請安裝樂動力~~");
} else if (SystemUtil.getAppVersionCode("cn.ledongli.ldl") <= 422) {
resultCallBack.onFailed("樂動力版本過低,請更新到4.2.2以上的版本");
} else {
registerReciver(activity);
activity.startService(wrapperedIntent);
}
}
}
示例6: startService
import android.app.Activity; //導入方法依賴的package包/類
public static void startService(Activity context, int requestCode, String input) {
Log.d(TAG, "startService");
PendingIntent pendingResult = context.createPendingResult(
requestCode, new Intent(), 0);
Intent intent = new Intent(context, DownloadIntentService.class);
intent.putExtra(DownloadIntentService.PENDING_RESULT_EXTRA, pendingResult);
intent.putExtra(DownloadIntentService.ID_EXTRA_INPUT, input);
context.startService(intent);
}
示例7: setupNmeaClientService
import android.app.Activity; //導入方法依賴的package包/類
private void setupNmeaClientService() {
final String tag="setupNmeaClientService - ";
if (isAdded()) {
final Activity activity=getActivity();
if (activity!=null) {
nmeaClientServiceConnection = new NmeaClientServiceConnection((ShipReceivedListener) this);
final Intent serviceIntent = new Intent(activity, NmeaClientService.class);
activity.startService(serviceIntent);
activity.bindService(new Intent(activity, NmeaClientService.class), nmeaClientServiceConnection, Context.BIND_AUTO_CREATE);
} else {
Log.e(TAG,tag+"Activity is null.");
}
}
}
示例8: requestPushToken
import android.app.Activity; //導入方法依賴的package包/類
void requestPushToken(Activity activity){
if (activity!=null) {
Intent service = new Intent(activity, RegistrationIntentService.class);
service.putExtra(RegistrationIntentService.TOKEN, "token");
activity.startService(service);
IntentFilter intentFilter = new IntentFilter(RegistrationIntentService.ACTION_TOKEN);
intentFilter.addCategory(Intent.CATEGORY_DEFAULT);
activity.registerReceiver(tokenBroadcastReceiver, intentFilter);
//send back first
sendBroatCast();
}
}
示例9: requestOpen
import android.app.Activity; //導入方法依賴的package包/類
static void requestOpen(Activity activity, DeviceFilter deviceFilter) {
Intent intent = new Intent(activity, DvbService.class)
.putExtra(DEVICE_FILTER, deviceFilter);
activity.startService(intent);
}
示例10: intentMergeService
import android.app.Activity; //導入方法依賴的package包/類
public static void intentMergeService(Activity activity, StickerAdapt2Result result) {
Intent intent = new Intent(activity, MergeService.class);
intent.putExtra(MERGE_DATA, result);
activity.startService(intent);
}