Example usage for android.content Context BIND_AUTO_CREATE

List of usage examples for android.content Context BIND_AUTO_CREATE

Introduction

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

Prototype

int BIND_AUTO_CREATE

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

Click Source Link

Document

Flag for #bindService : automatically create the service as long as the binding exists.

Usage

From source file:com.commonsware.android.advservice.callbackbinding.client.DownloadFragment.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setRetainInstance(true);//from w w  w.jav  a 2  s .  co m

    appContext = (Application) getActivity().getApplicationContext();

    Intent implicit = new Intent(IDownload.class.getName());
    List<ResolveInfo> matches = getActivity().getPackageManager().queryIntentServices(implicit, 0);

    if (matches.size() == 0) {
        Toast.makeText(getActivity(), "Cannot find a matching service!", Toast.LENGTH_LONG).show();
    } else if (matches.size() > 1) {
        Toast.makeText(getActivity(), "Found multiple matching services!", Toast.LENGTH_LONG).show();
    } else {
        Intent explicit = new Intent(implicit);
        ServiceInfo svcInfo = matches.get(0).serviceInfo;
        ComponentName cn = new ComponentName(svcInfo.applicationInfo.packageName, svcInfo.name);

        explicit.setComponent(cn);
        appContext.bindService(explicit, this, Context.BIND_AUTO_CREATE);
    }
}

From source file:net.olejon.mdapp.DonateActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // Connected?
    if (!mTools.isDeviceConnected()) {
        mTools.showToast(getString(R.string.device_not_connected), 1);

        finish();//from w  w w.j ava  2 s . c om

        return;
    }

    // Layout
    setContentView(R.layout.activity_donate);

    // Toolbar
    final Toolbar toolbar = (Toolbar) findViewById(R.id.donate_toolbar);
    toolbar.setTitle(getString(R.string.donate_title));

    setSupportActionBar(toolbar);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    // In-app billing
    Intent intent = new Intent("com.android.vending.billing.InAppBillingService.BIND");
    intent.setPackage("com.android.vending");

    bindService(intent, mServiceConnection, Context.BIND_AUTO_CREATE);

    // Buttons
    mMakeSmallDonationButton = (Button) findViewById(R.id.donate_make_small_donation);
    mMakeMediumDonationButton = (Button) findViewById(R.id.donate_make_medium_donation);
    mMakeBigDonationButton = (Button) findViewById(R.id.donate_make_big_donation);

    mMakeSmallDonationButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            makeDonation("small_donation");
        }
    });

    mMakeMediumDonationButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            makeDonation("medium_donation");
        }
    });

    mMakeBigDonationButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            makeDonation("big_donation");
        }
    });
}

From source file:net.olejon.spotcommander.DonateActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // Allow landscape?
    if (!mTools.allowLandscape())
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

    // Hide status bar?
    if (mTools.getDefaultSharedPreferencesBoolean("HIDE_STATUS_BAR"))
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);

    // Transition
    overridePendingTransition(R.anim.donate_start, R.anim.none);

    // Layout//from  ww  w . jav a2 s. co  m
    setContentView(R.layout.activity_donate);

    // Toolbar
    final Toolbar toolbar = (Toolbar) findViewById(R.id.donate_toolbar);

    setSupportActionBar(toolbar);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    // In-app billing
    Intent intent = new Intent("com.android.vending.billing.InAppBillingService.BIND");
    intent.setPackage("com.android.vending");
    bindService(intent, mServiceConnection, Context.BIND_AUTO_CREATE);
}

From source file:com.packpublishing.asynchronousandroid.chapter5.Sha1BroadcastUnhActivity.java

@Override
protected void onStart() {
    super.onStart();
    // Bind to LocalService
    Intent intent = new Intent(this, Sha1HashBroadCastUnhService.class);
    bindService(intent, mConnection, Context.BIND_AUTO_CREATE);
    mReceiver.attach((TextView) findViewById(R.id.hashResult));
    IntentFilter filter = new IntentFilter(Sha1HashBroadCastUnhService.DIGEST_BROADCAST);
    LocalBroadcastManager.getInstance(this).registerReceiver(mReceiver, filter);
}

From source file:com.secupwn.aimsicd.ui.fragments.DeviceFragment.java

@Override
public void onResume() {
    super.onResume();

    if (!mBound) {
        // Bind to LocalService
        Intent intent = new Intent(mContext, AimsicdService.class);
        mContext.bindService(intent, mConnection, Context.BIND_AUTO_CREATE);
    }//  w  w  w  .  j  a  va  2s .c  o  m
    updateUI();
}

From source file:net.named_data.accessmanager.MainActivity.java

@Override
protected void onStart() {
    super.onStart();
    // Bind to LocalService
    Intent intent = new Intent(this, AccessManagerService.class);
    bindService(intent, mConnection, Context.BIND_AUTO_CREATE);
}

From source file:com.coinblesk.client.wallet.WalletAddressList.java

@Override
public void onCreate(Bundle state) {
    super.onCreate(state);
    params = ((CoinbleskApp) getActivity().getApplication()).getAppConfig().getNetworkParameters();
    Intent walletServiceIntent = new Intent(getActivity(), WalletService.class);
    getActivity().bindService(walletServiceIntent, serviceConnection, Context.BIND_AUTO_CREATE);
    setHasOptionsMenu(true);// w w  w .  ja v a 2s  . c o  m
    adapter = new WalletAddressListAdapter(params);
    adapter.setItemClickListener(this);
}

From source file:cx.ring.client.AccountWizard.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_wizard);
    mViewPager = (ViewPager) findViewById(R.id.pager);

    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setHomeButtonEnabled(true);
    SectionsPagerAdapter mSectionsPagerAdapter = new SectionsPagerAdapter(AccountWizard.this,
            getFragmentManager());// ww  w .j a v a2s .c om
    mViewPager.setAdapter(mSectionsPagerAdapter);

    if (!mBound) {
        Log.i(TAG, "onCreate: Binding service...");
        Intent intent = new Intent(this, LocalService.class);
        bindService(intent, mConnection, Context.BIND_AUTO_CREATE);
    }

}

From source file:com.kevinshen.beyondupnp.ui.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    mBeyondApplication = (BeyondApplication) getApplication();

    mTabs = (PagerSlidingTabStrip) findViewById(R.id.tabs);
    mTabs.setShouldExpand(true);/*from  www  .j a va2 s  . c  o m*/

    mPager = (ViewPager) findViewById(R.id.pager);
    mPagerAdapter = new PagerAdapter(getFragmentManager());

    mPager.setAdapter(mPagerAdapter);
    mPager.setOffscreenPageLimit(2);

    mTabs.setViewPager(mPager);
    mTabs.setOnPageChangeListener(this);
    // Bind UPnP service
    Intent upnpServiceIntent = new Intent(MainActivity.this, BeyondUpnpService.class);
    bindService(upnpServiceIntent, mUpnpServiceConnection, Context.BIND_AUTO_CREATE);
    // Bind System service
    Intent systemServiceIntent = new Intent(MainActivity.this, SystemService.class);
    bindService(systemServiceIntent, mSystemServiceConnection, Context.BIND_AUTO_CREATE);
}

From source file:com.buddi.client.ModuleFragment.java

@Override
public void onAttach(Activity activity) {
    super.onAttach(activity);
    activity.getApplicationContext().bindService(new Intent(activity, BuddiBLEService.class), this,
            Context.BIND_AUTO_CREATE);
}