Example usage for android.content Context BIND_ADJUST_WITH_ACTIVITY

List of usage examples for android.content Context BIND_ADJUST_WITH_ACTIVITY

Introduction

In this page you can find the example usage for android.content Context BIND_ADJUST_WITH_ACTIVITY.

Prototype

int BIND_ADJUST_WITH_ACTIVITY

To view the source code for android.content Context BIND_ADJUST_WITH_ACTIVITY.

Click Source Link

Document

Flag for #bindService : If binding from an activity, allow the target service's process importance to be raised based on whether the activity is visible to the user, regardless whether another flag is used to reduce the amount that the client process's overall importance is used to impact it.

Usage

From source file:edu.umich.oasis.client.OASISConnection.java

public static ServiceConnection bind(final Context context, final Callback callback) {
    final ServiceConnection connection = new ServiceConnection() {
        private OASISConnection conn;

        @Override//from w ww  .j av a2 s  .co m
        public void onServiceConnected(ComponentName componentName, IBinder iBinder) {
            IOASISService service = IOASISService.Stub.asInterface(iBinder);
            conn = new OASISConnection(context, this, service);
            try {
                callback.onConnect(conn);
            } catch (Exception e) {
                Log.e(TAG, "Unhandled exception in onConnect", e);
            }
        }

        @Override
        public void onServiceDisconnected(ComponentName componentName) {
            Log.e(TAG, "Lost Binder connection to OASIS");
            if (callback instanceof DisconnectCallback) {
                try {
                    ((DisconnectCallback) callback).onDisconnect(conn);
                } catch (Exception e) {
                    Log.e(TAG, "Unhandled exception in onDisconnect", e);
                }
            }
            conn.closeInternal();
        }
    };

    Intent serviceIntent = new Intent();
    serviceIntent.setComponent(OASISFramework.getServiceComponent(context));
    if (context.bindService(serviceIntent, connection, Context.BIND_AUTO_CREATE
            | Context.BIND_ADJUST_WITH_ACTIVITY | Context.BIND_ABOVE_CLIENT | Context.BIND_IMPORTANT)) {
        return connection;
    } else {
        return null;
    }
}

From source file:com.bonsai.btcreceive.BaseWalletActivity.java

@SuppressLint("InlinedApi")
@Override//from  w w w . jav a 2 s . c  om
protected void onResume() {
    super.onResume();
    bindService(new Intent(this, WalletService.class), mConnection, Context.BIND_ADJUST_WITH_ACTIVITY);

    // Refetch the BTC format object in case it's changed.
    mBTCFmt = mApp.getBTCFmt();

    mLBM.registerReceiver(mWalletStateChangedReceiver, new IntentFilter("wallet-state-changed"));
    mLBM.registerReceiver(mRateChangedReceiver, new IntentFilter("rate-changed"));

    mLogger.info("BaseWalletActivity resumed");
}

From source file:com.bonsai.wallet32.BaseWalletActivity.java

@SuppressLint("InlinedApi")
@Override/*from   w  w w.  j a  va  2 s  .  co  m*/
protected void onResume() {
    super.onResume();

    mLogger.info("BaseWalletActivity resumed");

    mApp.cancelBackgroundTimeout();

    bindService(new Intent(this, WalletService.class), mConnection, Context.BIND_ADJUST_WITH_ACTIVITY);

    // Refetch the BTC format object in case it's changed.
    mBTCFmt = mApp.getBTCFmt();

    mLBM.registerReceiver(mWalletStateChangedReceiver, new IntentFilter("wallet-state-changed"));
    mLBM.registerReceiver(mRateChangedReceiver, new IntentFilter("rate-changed"));
}

From source file:com.bonsai.wallet32.PasscodeActivity.java

@SuppressLint("InlinedApi")
@Override/*from   w ww . j  a va 2s  . com*/
protected void onResume() {
    super.onResume();

    mLogger.info("PasscodeActivity resumed");

    mApp.cancelBackgroundTimeout();

    // NOTE - this passcode activity can happen on initial create
    // and login and the WalletService will not be started at that
    // time.  This is ok.
    //
    // We need a WalletService binding for the case where we change
    // the passcode and in this case it will be running ...
    //
    bindService(new Intent(this, WalletService.class), mConnection, Context.BIND_ADJUST_WITH_ACTIVITY);

    mIsPaused = false;

    // Did we have an invalid passcode attempt complete while paused?
    if (mPasscodeWasInvalid) {
        mLogger.info("showing deferred passcode invalid dialog");
        mPasscodeWasInvalid = false;
        showPasscodeInvalidDialog();
    }
}

From source file:by.zatta.pilight.MainActivity.java

/**
 * Bind this Activity to MyService//from ww w. java2 s . c  o m
 */
private void doBindService() {
    bindService(new Intent(this, ConnectionService.class), mConnection, Context.BIND_ADJUST_WITH_ACTIVITY);
    mIsBound = true;
}

From source file:org.opendatakit.survey.android.activities.MainMenuActivity.java

@SuppressLint("InlinedApi")
@Override//from w ww . j  av a  2  s. c  om
protected void onStart() {
    super.onStart();

    // ensure the DbShimService is started
    Intent intent = new Intent(this, DbShimService.class);
    this.startService(intent);

    this.bindService(intent, mConnection,
            Context.BIND_AUTO_CREATE | ((Build.VERSION.SDK_INT >= 14) ? Context.BIND_ADJUST_WITH_ACTIVITY : 0));

    FrameLayout shadow = (FrameLayout) findViewById(R.id.shadow_content);
    View frags = findViewById(R.id.main_content);
    ODKWebView wkt = (ODKWebView) findViewById(R.id.webkit_view);

    if (currentFragment == ScreenList.FORM_CHOOSER || currentFragment == ScreenList.FORM_DOWNLOADER
            || currentFragment == ScreenList.FORM_DELETER
            || currentFragment == ScreenList.INSTANCE_UPLOADER_TABLE_CHOOSER
            || currentFragment == ScreenList.INSTANCE_UPLOADER
            || currentFragment == ScreenList.INITIALIZATION_DIALOG) {
        shadow.setVisibility(View.GONE);
        shadow.removeAllViews();
        wkt.setVisibility(View.GONE);
        frags.setVisibility(View.VISIBLE);
    } else if (currentFragment == ScreenList.WEBKIT) {
        shadow.setVisibility(View.GONE);
        shadow.removeAllViews();
        wkt.setVisibility(View.VISIBLE);
        wkt.invalidate();
        frags.setVisibility(View.GONE);
    } else if (currentFragment == ScreenList.CUSTOM_VIEW) {
        shadow.setVisibility(View.VISIBLE);
        // shadow.removeAllViews();
        wkt.setVisibility(View.GONE);
        frags.setVisibility(View.GONE);
    }

    FragmentManager mgr = getFragmentManager();
    if (mgr.getBackStackEntryCount() == 0) {
        swapToFragmentView(currentFragment);
    }
}

From source file:org.path.episample.android.activities.MainMenuActivity.java

@SuppressLint("InlinedApi")
@Override// ww  w  .j a  v  a2s.c  om
protected void onStart() {
    super.onStart();

    // ensure the DbShimService is started
    Intent intent = new Intent(this, DbShimService.class);
    this.startService(intent);

    this.bindService(intent, mConnection,
            Context.BIND_AUTO_CREATE | ((Build.VERSION.SDK_INT >= 14) ? Context.BIND_ADJUST_WITH_ACTIVITY : 0));

    FrameLayout shadow = (FrameLayout) findViewById(R.id.shadow_content);
    View frags = findViewById(R.id.main_content);
    ODKWebView wkt = (ODKWebView) findViewById(R.id.webkit_view);

    if (currentFragment == ScreenList.MAIN_MENU || currentFragment == ScreenList.COLLECT_MODULE
            || currentFragment == ScreenList.SEND_RECEIVE_WIFI_DIRECT_MODULE
            || currentFragment == ScreenList.SEND_RECEIVE_BLUETOOTH_MODULE
            || currentFragment == ScreenList.SELECT_MODULE || currentFragment == ScreenList.NAVIGATE_MODULE
            || currentFragment == ScreenList.RESTORE_MODULE || currentFragment == ScreenList.EDIT_CENSUS_MODULE
            || currentFragment == ScreenList.REMOVE_CENSUS_MODULE
            || currentFragment == ScreenList.INVALIDATE_CENSUS_MODULE
            || currentFragment == ScreenList.FORM_CHOOSER || currentFragment == ScreenList.FORM_DOWNLOADER
            || currentFragment == ScreenList.FORM_DELETER
            || currentFragment == ScreenList.INSTANCE_UPLOADER_TABLE_CHOOSER
            || currentFragment == ScreenList.INSTANCE_UPLOADER
            || currentFragment == ScreenList.INITIALIZATION_DIALOG) {
        shadow.setVisibility(View.GONE);
        shadow.removeAllViews();
        wkt.setVisibility(View.GONE);
        frags.setVisibility(View.VISIBLE);
    } else if (currentFragment == ScreenList.WEBKIT) {
        shadow.setVisibility(View.GONE);
        shadow.removeAllViews();
        wkt.setVisibility(View.VISIBLE);
        wkt.invalidate();
        frags.setVisibility(View.GONE);
    } else if (currentFragment == ScreenList.CUSTOM_VIEW) {
        shadow.setVisibility(View.VISIBLE);
        // shadow.removeAllViews();
        wkt.setVisibility(View.GONE);
        frags.setVisibility(View.GONE);
    }

    FragmentManager mgr = getFragmentManager();
    if (mgr.getBackStackEntryCount() == 0) {
        swapToFragmentView(currentFragment);
    }
}