@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); }
@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"); }
@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); }
@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); }
@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); }
@Override public void onClick(View v) { // Easy way to delete a service final Activity activity = getActivity(); activity.stopService(new Intent(activity, CustomFloatingViewService.class)); } });
/** * @param name * @return * @see android.content.ContextWrapper#stopService(android.content.Intent) */ public boolean stopService(Intent name) { return mActivity.stopService(name); }
public void onClick(View v) { mActivity.stopService(new Intent(mActivity, mClz)); } };
public void onClick(View v) { mActivity.stopService(new Intent(mActivity, mClz)); } };
private void stopFloatingBubbleService() { Intent floatingBubbleServiceIntent = new Intent(getActivity().getApplicationContext(), FloatingBubbleService.class); getActivity().stopService(floatingBubbleServiceIntent); } }
private void stopService() { getActivity().stopService(new Intent(getActivity().getApplicationContext(), NetTrafficService.class)); }
private void stopClipService() { Intent clipServiceIntent = new Intent(getActivity().getApplicationContext(), ClipboardService.class); getActivity().stopService(clipServiceIntent); }
@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); } }
@Override public void onDestroy() { super.onDestroy(); if (getActivity().isFinishing()) { final Activity activity = getActivity(); final Intent service = new Intent(activity, UpdateService.class); activity.stopService(service); } }
activity.stopService(service); mBinder = null; mBinded = false;
.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));
@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); }