本文整理了Java中android.app.Activity.stopService()
方法的一些代码示例,展示了Activity.stopService()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Activity.stopService()
方法的具体详情如下:
包路径:android.app.Activity
类名称:Activity
方法名:stopService
暂无
代码示例来源: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: commonsguy/cw-omnibus
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getActivity().stopService(new Intent(getActivity(),
LocationPollerService.class));
addPreferencesFromResource(R.xml.prefs);
Preference pref=findPreference("delay");
updateSummary((ListPreference)pref,
pref.getSharedPreferences().getString(pref.getKey(), null));
pref.setOnPreferenceChangeListener(
new Preference.OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference pref,
Object newValue) {
updateSummary((ListPreference)pref, newValue.toString());
return(true);
}
});
pref=findPreference("running");
((SwitchPreference)pref).setChecked(false);
pref.setOnPreferenceChangeListener(this);
}
代码示例来源:origin: robolectric/robolectric
@Test
public void shouldHaveStoppedServiceIntentAndIndicateServiceWasntRunning() {
ShadowApplication shadowApplication = Shadows.shadowOf(context);
Activity activity = Robolectric.setupActivity(Activity.class);
Intent intent = getSomeActionIntent("some.action");
boolean wasRunning = activity.stopService(intent);
assertFalse(wasRunning);
assertThat(shadowApplication.getNextStoppedService()).isEqualTo(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: recruit-lifestyle/FloatingView
@Override
public void onClick(View v) {
// Easy way to delete a service
final Activity activity = getActivity();
activity.stopService(new Intent(activity, CustomFloatingViewService.class));
}
});
代码示例来源:origin: com.uphyca/android-junit4-robolectric
/**
* @param name
* @return
* @see android.content.ContextWrapper#stopService(android.content.Intent)
*/
public boolean stopService(Intent name) {
return mActivity.stopService(name);
}
代码示例来源:origin: qiubiteme/android_api_demos
public void onClick(View v) {
mActivity.stopService(new Intent(mActivity, mClz));
}
};
代码示例来源:origin: li2/learning-android-open-source
public void onClick(View v) {
mActivity.stopService(new Intent(mActivity, mClz));
}
};
代码示例来源:origin: tunjos/SearchBubble
private void stopFloatingBubbleService() {
Intent floatingBubbleServiceIntent = new Intent(getActivity().getApplicationContext(), FloatingBubbleService.class);
getActivity().stopService(floatingBubbleServiceIntent);
}
}
代码示例来源:origin: by-syk/NetUpDown
private void stopService() {
getActivity().stopService(new Intent(getActivity().getApplicationContext(), NetTrafficService.class));
}
代码示例来源:origin: tunjos/SearchBubble
private void stopClipService() {
Intent clipServiceIntent = new Intent(getActivity().getApplicationContext(), ClipboardService.class);
getActivity().stopService(clipServiceIntent);
}
代码示例来源: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: NordicSemiconductor/Android-nRF-Beacon
@Override
public void onDestroy() {
super.onDestroy();
if (getActivity().isFinishing()) {
final Activity activity = getActivity();
final Intent service = new Intent(activity, UpdateService.class);
activity.stopService(service);
}
}
代码示例来源:origin: NordicSemiconductor/Android-nRF-Beacon
activity.stopService(service);
mBinder = null;
mBinded = false;
代码示例来源:origin: rsiebert/TVHClient
.onPositive((dialog, which) -> {
Timber.d("Reconnect requested, stopping service and updating active connection to require a full sync");
activity.stopService(new Intent(activity, EpgSyncService.class));
代码示例来源:origin: iqiyi/Neptune
@Override
public boolean stopService(Intent name) {
PluginDebugLog.runtimeLog(TAG, "InstrActivityProxy1 stopService....");
if (mLoadedApk != null) {
String mTargetServiceName = null;
if (name.getComponent() != null) {
mTargetServiceName = name.getComponent().getClassName();
} else {
PluginPackageInfo mInfo = mLoadedApk.getPluginPackageInfo();
ServiceInfo mServiceInfo = mInfo.resolveService(name);
if (mServiceInfo != null) {
mTargetServiceName = mServiceInfo.name;
}
}
if (!TextUtils.isEmpty(mTargetServiceName)) {
PluginServiceWrapper plugin = PServiceSupervisor.getServiceByIdentifer(
PluginServiceWrapper.getIdentify(mLoadedApk.getPluginPackageName(),
mTargetServiceName));
if (plugin != null) {
plugin.updateServiceState(PluginServiceWrapper.PLUGIN_SERVICE_STOPED);
plugin.tryToDestroyService();
return true;
}
}
}
return super.stopService(name);
}
内容来源于网络,如有侵权,请联系作者删除!