Java Code Examples for android.content.Context#unbindService()
The following examples show how to use
android.content.Context#unbindService() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CustomTabsClient.java From 365browser with Apache License 2.0 | 6 votes |
/** * Connects to the Custom Tabs warmup service, and initializes the browser. * * This convenience method connects to the service, and immediately warms up the Custom Tabs * implementation. Since service connection is asynchronous, the return code is not the return * code of warmup. * This call is optional, and clients are encouraged to connect to the service, call * <code>warmup()</code> and create a session. In this case, calling this method is not * necessary. * * @param context {@link Context} to use to connect to the remote service. * @param packageName Package name of the target implementation. * @return Whether the binding was successful. */ public static boolean connectAndInitialize(Context context, String packageName) { if (packageName == null) return false; final Context applicationContext = context.getApplicationContext(); CustomTabsServiceConnection connection = new CustomTabsServiceConnection() { @Override public final void onCustomTabsServiceConnected( ComponentName name, CustomTabsClient client) { client.warmup(0); // Unbinding immediately makes the target process "Empty", provided that it is // not used by anyone else, and doesn't contain any Activity. This makes it // likely to get killed, but is preferable to keeping the connection around. applicationContext.unbindService(this); } @Override public final void onServiceDisconnected(ComponentName componentName) { } }; try { return bindCustomTabsService(applicationContext, packageName, connection); } catch (SecurityException e) { return false; } }
Example 2
Source File: AsyncServiceHelper.java From FtcSamples with MIT License | 6 votes |
public static boolean initOpenCV(String Version, final Context AppContext, final LoaderCallbackInterface Callback) { AsyncServiceHelper helper = new AsyncServiceHelper(Version, AppContext, Callback); Intent intent = new Intent("org.opencv.engine.BIND"); intent.setPackage("org.opencv.engine"); if (AppContext.bindService(intent, helper.mServiceConnection, Context.BIND_AUTO_CREATE)) { return true; } else { AppContext.unbindService(helper.mServiceConnection); InstallService(AppContext, Callback); return false; } }
Example 3
Source File: CustomTabsClient.java From TelePlus-Android with GNU General Public License v2.0 | 6 votes |
/** * Connects to the Custom Tabs warmup service, and initializes the browser. * * This convenience method connects to the service, and immediately warms up the Custom Tabs * implementation. Since service connection is asynchronous, the return code is not the return * code of warmup. * This call is optional, and clients are encouraged to connect to the service, call * <code>warmup()</code> and create a session. In this case, calling this method is not * necessary. * * @param context {@link Context} to use to connect to the remote service. * @param packageName Package name of the target implementation. * @return Whether the binding was successful. */ public static boolean connectAndInitialize(Context context, String packageName) { if (packageName == null) return false; final Context applicationContext = context.getApplicationContext(); CustomTabsServiceConnection connection = new CustomTabsServiceConnection() { @Override public final void onCustomTabsServiceConnected( ComponentName name, CustomTabsClient client) { client.warmup(0); // Unbinding immediately makes the target process "Empty", provided that it is // not used by anyone else, and doesn't contain any Activity. This makes it // likely to get killed, but is preferable to keeping the connection around. applicationContext.unbindService(this); } @Override public final void onServiceDisconnected(ComponentName componentName) { } }; try { return bindCustomTabsService(applicationContext, packageName, connection); } catch (SecurityException e) { return false; } }
Example 4
Source File: AsyncServiceHelper.java From ResistorScanner with MIT License | 6 votes |
public static boolean initOpenCV(String Version, final Context AppContext, final LoaderCallbackInterface Callback) { AsyncServiceHelper helper = new AsyncServiceHelper(Version, AppContext, Callback); Intent intent = new Intent("org.opencv.engine.BIND"); intent.setPackage("org.opencv.engine"); if (AppContext.bindService(intent, helper.mServiceConnection, Context.BIND_AUTO_CREATE)) { return true; } else { AppContext.unbindService(helper.mServiceConnection); InstallService(AppContext, Callback); return false; } }
Example 5
Source File: AsyncServiceHelper.java From pasm-yolov3-Android with GNU General Public License v3.0 | 6 votes |
public static boolean initOpenCV(String Version, final Context AppContext, final LoaderCallbackInterface Callback) { AsyncServiceHelper helper = new AsyncServiceHelper(Version, AppContext, Callback); Intent intent = new Intent("org.opencv.engine.BIND"); intent.setPackage("org.opencv.engine"); if (AppContext.bindService(intent, helper.mServiceConnection, Context.BIND_AUTO_CREATE)) { return true; } else { AppContext.unbindService(helper.mServiceConnection); InstallService(AppContext, Callback); return false; } }
Example 6
Source File: TrojanConnection.java From igniter with GNU General Public License v3.0 | 6 votes |
public void disconnect(Context context) { unregisterServiceCallback(); if (mAlreadyConnected) { try { context.unbindService(this); } catch (IllegalArgumentException e) { e.printStackTrace(); } mAlreadyConnected = false; if (mListenToDeath && mBinder != null) { mBinder.unlinkToDeath(this, 0); } mBinder = null; mTrojanService = null; mCallback = null; } }
Example 7
Source File: ServiceLifecycleTest.java From android_9.0.0_r45 with Apache License 2.0 | 6 votes |
@Test public void testStartBindUnbindStop() throws InterruptedException { Context context = InstrumentationRegistry.getTargetContext(); context.startService(mServiceIntent); awaitAndAssertEvents(ON_CREATE, ON_START); ServiceConnection connection = bindToService(); // Precaution: give a chance to dispatch events InstrumentationRegistry.getInstrumentation().waitForIdleSync(); // still the same events awaitAndAssertEvents(ON_CREATE, ON_START); context.unbindService(connection); // Precaution: give a chance to dispatch events InstrumentationRegistry.getInstrumentation().waitForIdleSync(); // service is still started (stopServices/stopSelf weren't called) awaitAndAssertEvents(ON_CREATE, ON_START); context.stopService(mServiceIntent); awaitAndAssertEvents(ON_CREATE, ON_START, ON_STOP, ON_DESTROY); }
Example 8
Source File: AsyncServiceHelper.java From FTCVision with MIT License | 6 votes |
public static boolean initOpenCV(String Version, final Context AppContext, final LoaderCallbackInterface Callback) { AsyncServiceHelper helper = new AsyncServiceHelper(Version, AppContext, Callback); Intent intent = new Intent("org.opencv.engine.BIND"); intent.setPackage("org.opencv.engine"); if (AppContext.bindService(intent, helper.mServiceConnection, Context.BIND_AUTO_CREATE)) { return true; } else { AppContext.unbindService(helper.mServiceConnection); InstallService(AppContext, Callback); return false; } }
Example 9
Source File: CaseReplayManager.java From SoloPi with Apache License 2.0 | 6 votes |
/** * 停止replay */ public void onDestroy(Context context) { this.provider = null; eventService.stopTrackAccessibilityEvent(); if (watcher != null) { watcher.stop(); watcher = null; } if (connection != null) { context.unbindService(connection); connection = null; binder = null; } runningExecutor.shutdownNow(); LauncherApplication.getInstance().stopServiceByName(HighLightService.class.getName()); }
Example 10
Source File: CustomTabsClient.java From Telegram-FOSS with GNU General Public License v2.0 | 6 votes |
/** * Connects to the Custom Tabs warmup service, and initializes the browser. * * This convenience method connects to the service, and immediately warms up the Custom Tabs * implementation. Since service connection is asynchronous, the return code is not the return * code of warmup. * This call is optional, and clients are encouraged to connect to the service, call * <code>warmup()</code> and create a session. In this case, calling this method is not * necessary. * * @param context {@link Context} to use to connect to the remote service. * @param packageName Package name of the target implementation. * @return Whether the binding was successful. */ public static boolean connectAndInitialize(Context context, String packageName) { if (packageName == null) return false; final Context applicationContext = context.getApplicationContext(); CustomTabsServiceConnection connection = new CustomTabsServiceConnection() { @Override public final void onCustomTabsServiceConnected( ComponentName name, CustomTabsClient client) { client.warmup(0); // Unbinding immediately makes the target process "Empty", provided that it is // not used by anyone else, and doesn't contain any Activity. This makes it // likely to get killed, but is preferable to keeping the connection around. applicationContext.unbindService(this); } @Override public final void onServiceDisconnected(ComponentName componentName) { } }; try { return bindCustomTabsService(applicationContext, packageName, connection); } catch (SecurityException e) { return false; } }
Example 11
Source File: AsyncServiceHelper.java From faceswap with Apache License 2.0 | 6 votes |
public static boolean initOpenCV(String Version, final Context AppContext, final LoaderCallbackInterface Callback) { AsyncServiceHelper helper = new AsyncServiceHelper(Version, AppContext, Callback); Intent intent = new Intent("org.opencv.engine.BIND"); intent.setPackage("org.opencv.engine"); if (AppContext.bindService(intent, helper.mServiceConnection, Context.BIND_AUTO_CREATE)) { return true; } else { AppContext.unbindService(helper.mServiceConnection); InstallService(AppContext, Callback); return false; } }
Example 12
Source File: PumpPluginAbstract.java From AndroidAPS with GNU Affero General Public License v3.0 | 5 votes |
@Override protected void onStop() { Context context = MainApp.instance().getApplicationContext(); context.unbindService(serviceConnection); serviceRunning = false; disposable.clear(); super.onStop(); }
Example 13
Source File: PostMessageServiceConnection.java From custom-tabs-client with Apache License 2.0 | 5 votes |
/** * Unbinds this service connection from the given context. * @param context The context to be unbound from. */ public void unbindFromContext(Context context) { if (isBoundToService()) { context.unbindService(this); mService = null; } }
Example 14
Source File: DvbServiceImpl.java From TvLauncher with Apache License 2.0 | 5 votes |
public static synchronized void deInit(Context context) { if (instance != null) { Log.i(TAG, "deInit..."); context.unbindService(mRemoteConnection); instance = null; } }
Example 15
Source File: DNSCryptFragmentPresenter.java From InviZible with GNU General Public License v3.0 | 5 votes |
private void unbindVPNService(Context context) { if (bound && serviceConnection != null && context != null) { try { context.unbindService(serviceConnection); } catch (Exception e) { Log.w(LOG_TAG, "DNSCryptFragmentPresenter unbindVPNService exception " + e.getMessage() + " " + e.getCause()); } bound = false; } }
Example 16
Source File: BumpMonitor.java From haven with GNU General Public License v3.0 | 4 votes |
public void stop(Context context) { sensorMgr.cancelTriggerSensor(sensorListener, bumpSensor); context.unbindService(mConnection); }
Example 17
Source File: AccelerometerMonitor.java From haven with GNU General Public License v3.0 | 4 votes |
public void stop(Context context) { sensorMgr.unregisterListener(this); context.unbindService(mConnection); }
Example 18
Source File: Galgo.java From RxAndroidBootstrap with Apache License 2.0 | 4 votes |
public static void disable(Context context) { context.unbindService(sConnection); }
Example 19
Source File: TestButler.java From test-butler with Apache License 2.0 | 3 votes |
/** * Stop the remote ButlerService to indicate the test run has completed. * <p> * This method should be called from a subclass of {@link Instrumentation#finish(int, Bundle)}, BEFORE * calling super.finish(). Often this will be a subclass of AndroidJUnitRunner. * <p> * This will handle re-enabling animations on the device, as well as allow system popups to be shown when * apps crash or ANR on the emulator. * * @param context the "target context"; i.e. Context of the app under test (not the test apk context!) */ public static void teardown(@NonNull Context context) { Intent intent = new Intent(); intent.setComponent(new ComponentName("com.linkedin.android.testbutler", "com.linkedin.android.testbutler.ButlerService")); context.unbindService(serviceConnection); serviceStarted = new CountDownLatch(1); }
Example 20
Source File: PostMessageServiceConnection.java From Telegram-FOSS with GNU General Public License v2.0 | 2 votes |
/** * Unbinds this service connection from the given context. * @param context The context to be unbound from. */ public void unbindFromContext(Context context) { context.unbindService(this); }