android.app.Activity.startService()方法的使用及代码示例

x33g5p2x  于2022-01-15 转载在 其他  
字(7.9k)|赞(0)|评价(0)|浏览(156)

本文整理了Java中android.app.Activity.startService()方法的一些代码示例,展示了Activity.startService()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Activity.startService()方法的具体详情如下:
包路径:android.app.Activity
类名称:Activity
方法名:startService

Activity.startService介绍

暂无

代码示例

代码示例来源:origin: aa112901/remusic

@Override
  public void onClick(View v) {
    Intent intent = new Intent(DownService.CANCLE_ALL_DOWNTASK);
    intent.setPackage(IConstants.PACKAGE);
    mContext.startService(intent);
  }
});

代码示例来源:origin: aa112901/remusic

@Override
  public void onClick(View v) {
    Intent intent = new Intent(DownService.START_ALL_DOWNTASK);
    intent.setPackage(IConstants.PACKAGE);
    mContext.startService(intent);
  }
});

代码示例来源:origin: aa112901/remusic

@Override
  public void onClick(View v) {
    Intent intent = new Intent(DownService.PAUSE_ALLTASK);
    intent.setPackage(IConstants.PACKAGE);
    mContext.startService(intent);
  }
});

代码示例来源:origin: aa112901/remusic

@Override
  public void onClick(View v) {
    if (isPreparing1) {
      L.D(d, TAG, "isprepaing");
      Intent intent = new Intent(DownService.PAUSE_TASK);
      intent.setPackage(IConstants.PACKAGE);
      intent.putExtra("downloadid", task.getDownloadId());
      mContext.startService(intent);
    } else {
      L.D(d, TAG, "not isprepaing");
      Intent intent = new Intent(DownService.RESUME_START_DOWNTASK);
      intent.setPackage(IConstants.PACKAGE);
      intent.putExtra("downloadid", task.getDownloadId());
      mContext.startService(intent);
    }
  }
});

代码示例来源:origin: seven332/EhViewer

Intent intent = new Intent(activity, DownloadService.class);
intent.setAction(DownloadService.ACTION_START_ALL);
activity.startService(intent);
return true;

代码示例来源:origin: seven332/EhViewer

intent.setAction(DownloadService.ACTION_START);
  intent.putExtra(DownloadService.KEY_GALLERY_INFO, list.get(index));
  activity.startService(intent);
} else if (stop == v) {
  if (null != mDownloadManager) {

代码示例来源:origin: commonsguy/cw-omnibus

@Override
public boolean onPreferenceChange(Preference pref, Object newValue) {
 Boolean value=(Boolean)newValue;
 Intent i=new Intent(getActivity(), LocationPollerService.class);
 if (value) {
  if (Build.VERSION.SDK_INT>Build.VERSION_CODES.N_MR1) {
   getActivity().startForegroundService(i);
  }
  else {
   getActivity().startService(i);
  }
 }
 else {
  getActivity().stopService(i);
 }
 getActivity().finish();
 return(true);
}

代码示例来源:origin: robolectric/robolectric

@Test
public void shouldHaveStoppedServiceByStartedComponent() {
 ShadowApplication shadowApplication = shadowOf(context);
 Activity activity = Robolectric.setupActivity(Activity.class);
 ComponentName componentName = new ComponentName("package.test", "package.test.TestClass");
 Intent startServiceIntent = new Intent().setComponent(componentName);
 ComponentName startedComponent = activity.startService(startServiceIntent);
 assertThat(startedComponent.getPackageName()).isEqualTo("package.test");
 assertThat(startedComponent.getClassName()).isEqualTo("package.test.TestClass");
 Intent stopServiceIntent = new Intent().setComponent(startedComponent);
 stopServiceIntent.putExtra("someExtra", "someValue");
 boolean wasRunning = activity.stopService(stopServiceIntent);
 assertTrue(wasRunning);
 final Intent nextStoppedService = shadowApplication.getNextStoppedService();
 assertThat(nextStoppedService.filterEquals(startServiceIntent)).isTrue();
 assertThat(nextStoppedService.getStringExtra("someExtra")).isEqualTo("someValue");
}

代码示例来源:origin: seven332/EhViewer

intent.setAction(DownloadService.ACTION_START_RANGE);
intent.putExtra(DownloadService.KEY_GID_LIST, gidList);
activity.startService(intent);

代码示例来源:origin: robolectric/robolectric

@Test
public void shouldHaveStoppedServiceIntentAndIndicateServiceWasRunning() {
 ShadowApplication shadowApplication = shadowOf(context);
 Activity activity = Robolectric.setupActivity(Activity.class);
 Intent intent = getSomeActionIntent("some.action");
 activity.startService(intent);
 boolean wasRunning = activity.stopService(intent);
 assertTrue(wasRunning);
 assertThat(shadowApplication.getNextStoppedService()).isEqualTo(intent);
}

代码示例来源:origin: syncthing/syncthing-android

.setMessage(R.string.st_reset_database_question)
.setPositiveButton(android.R.string.ok, (dialogInterface, i) -> {
  getActivity().startService(intent);
  Toast.makeText(getActivity(), R.string.st_reset_database_done, Toast.LENGTH_LONG).show();
})
.setMessage(R.string.st_reset_deltas_question)
.setPositiveButton(android.R.string.ok, (dialogInterface, i) -> {
  getActivity().startService(intent);
  Toast.makeText(getActivity(), R.string.st_reset_deltas_done, Toast.LENGTH_LONG).show();
})

代码示例来源:origin: schaal/ocreader

public static void startSync(Activity activity, boolean initialSync) {
  Intent syncIntent = new Intent(ACTION_SYNC, null, activity, SyncService.class);
  syncIntent.putExtra(EXTRA_TYPE, SyncType.FULL_SYNC.action);
  syncIntent.putExtra(EXTRA_INITIAL_SYNC, initialSync);
  activity.startService(syncIntent);
}

代码示例来源:origin: y20k/transistor

@Override
  public void onClick(View view) {
    // stop sleep timer service using intent
    Intent intent = new Intent(mActivity, SleepTimerService.class);
    intent.setAction(ACTION_TIMER_STOP);
    mActivity.startService(intent);
    mSleepTimerRunning = false;
    // notify user
    Toast.makeText(mActivity, mActivity.getString(R.string.toastmessage_timer_cancelled), Toast.LENGTH_SHORT).show();
    LogHelper.v(LOG_TAG, "Sleep timer cancelled.");
  }
});

代码示例来源:origin: NordicSemiconductor/Android-nRF-Beacon

@Override
public void onDeviceSelected(final BluetoothDevice device, final String name) {
  final Activity activity = getActivity();
  final Intent service = new Intent(activity, UpdateService.class);
  service.putExtra(UpdateService.EXTRA_DATA, device);
  activity.startService(service);
  mBinded = true;
  activity.bindService(service, mServiceConnection, 0);
}

代码示例来源:origin: iqiyi/Neptune

@Override
public ComponentName startService(Intent mIntent) {
  PluginDebugLog.runtimeLog(TAG, "InstrActivityProxy1 startService....");
  if (mLoadedApk != null) {
    ComponentFinder.switchToServiceProxy(mLoadedApk, mIntent);
  }
  return super.startService(mIntent);
}

代码示例来源:origin: thuryn/your-local-weather

@Override
  public boolean onPreferenceChange(Preference preference, Object o) {
    boolean isEnabled = (boolean) o;
    AppPreference.setNotificationEnabled(getActivity(), isEnabled);
    Intent intentToStartUpdate = new Intent("org.thosp.yourlocalweather.action.RESTART_NOTIFICATION_ALARM_SERVICE");
    intentToStartUpdate.setPackage("org.thosp.yourlocalweather");
    getActivity().startService(intentToStartUpdate);
    return true;
  }
};

代码示例来源:origin: shkcodes/Lyrically

@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
  // changes made to these preference will be reflected instantly in the trigger; for others, restart the service
  if (!(key.equals("triggerOffset") || key.equals("triggerWidth") || key.equals("triggerHeight"))) {
    Intent intent = new Intent(getActivity(), PreferenceTrigger.class);
    getActivity().stopService(intent);
    getActivity().startService(intent);
  }
}

代码示例来源:origin: robohorse/gpversionchecker

@Test
public void testCheckAndStartService_for_always_strategy() throws Exception {
  manager.checkAndStartService(activity, CheckingStrategy.ALWAYS);
  verify(activity, atLeastOnce()).startService(new Intent(activity, VersionCheckerService.class));
}

代码示例来源:origin: robohorse/gpversionchecker

@Test
public void testCheckAndStartService_for_one_per_day_strategy() throws Exception {
  when(sharedDataProvider.provideLastCheckTime()).thenReturn(new Date().getTime() - TimeUnit.HOURS.toMillis(2));
  when(formatUtils.formatTodayDate()).thenReturn(new Date());
  manager.checkAndStartService(activity, CheckingStrategy.ONE_PER_DAY);
  verify(activity, atLeastOnce()).startService(new Intent(activity, VersionCheckerService.class));
}

代码示例来源:origin: robohorse/gpversionchecker

@Test
public void testCheckAndStartService_for_one_per_version_per_day_strategy() throws Exception {
  when(sharedDataProvider.provideLastCheckTime()).thenReturn(new Date().getTime() - TimeUnit.HOURS.toMillis(2));
  when(formatUtils.formatTodayDate()).thenReturn(new Date());
  manager.checkAndStartService(activity, CheckingStrategy.ONE_PER_VERSION_PER_DAY);
  verify(activity, atLeastOnce()).startService(new Intent(activity, VersionCheckerService.class));
}

相关文章

微信公众号

最新文章

更多

Activity类方法