本文整理汇总了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);
}