android.content.Context#unbindService ( )源码实例Demo

下面列出了android.content.Context#unbindService ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: faceswap   文件: AsyncServiceHelper.java
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;
    }
}
 
源代码2 项目: 365browser   文件: CustomTabsClient.java
/**
 * 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;
    }
}
 
源代码3 项目: Telegram-FOSS   文件: CustomTabsClient.java
/**
 * 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;
    }
}
 
源代码4 项目: SoloPi   文件: CaseReplayManager.java
/**
 * 停止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());
}
 
源代码5 项目: FTCVision   文件: AsyncServiceHelper.java
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;
    }
}
 
源代码6 项目: android_9.0.0_r45   文件: ServiceLifecycleTest.java
@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);
}
 
源代码7 项目: igniter   文件: TrojanConnection.java
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;
    }
}
 
源代码8 项目: pasm-yolov3-Android   文件: AsyncServiceHelper.java
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;
    }
}
 
源代码9 项目: ResistorScanner   文件: AsyncServiceHelper.java
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;
    }
}
 
源代码10 项目: TelePlus-Android   文件: CustomTabsClient.java
/**
 * 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;
    }
}
 
源代码11 项目: FtcSamples   文件: AsyncServiceHelper.java
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;
    }
}
 
源代码12 项目: TvLauncher   文件: DvbServiceImpl.java
public static synchronized void deInit(Context context) {
    if (instance != null) {
        Log.i(TAG, "deInit...");
        context.unbindService(mRemoteConnection);
        instance = null;
    }
}
 
源代码13 项目: AndroidAPS   文件: PumpPluginAbstract.java
@Override
protected void onStop() {
    Context context = MainApp.instance().getApplicationContext();
    context.unbindService(serviceConnection);

    serviceRunning = false;

    disposable.clear();
    super.onStop();
}
 
/**
 * 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;
    }
}
 
源代码15 项目: InviZible   文件: DNSCryptFragmentPresenter.java
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;
    }
}
 
源代码16 项目: RxAndroidBootstrap   文件: Galgo.java
public static void disable(Context context) {
    context.unbindService(sConnection);
}
 
源代码17 项目: haven   文件: BumpMonitor.java
public void stop(Context context) {
    sensorMgr.cancelTriggerSensor(sensorListener, bumpSensor);
    context.unbindService(mConnection);
}
 
源代码18 项目: haven   文件: AccelerometerMonitor.java
public void stop(Context context) {
    sensorMgr.unregisterListener(this);
    context.unbindService(mConnection);
}
 
源代码19 项目: test-butler   文件: TestButler.java
/**
 * 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);
}
 
/**
 * Unbinds this service connection from the given context.
 * @param context The context to be unbound from.
 */
public void unbindFromContext(Context context) {
    context.unbindService(this);
}
 
 方法所在类
 同类方法