Example usage for android.content Context BIND_NOT_FOREGROUND

List of usage examples for android.content Context BIND_NOT_FOREGROUND

Introduction

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

Prototype

int BIND_NOT_FOREGROUND

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

Click Source Link

Document

Flag for #bindService : don't allow this binding to raise the target service's process to the foreground scheduling priority.

Usage

From source file:com.drinviewer.droiddrinviewer.ServerListFragment.java

/**
 * onResume Fragment method/*from  ww w. ja v  a  2s .  c  om*/
 */
@Override
public void onResume() {
    super.onResume();
    mustUpdateUI = true;

    try {
        if (discoverServerApi != null) {
            /**
             *  if the service is doing a discovery, just set the
             *  discoverServerProgress visibility to visible. 
             *  The service will call the listener when it has finished
             */
            if (discoverServerApi.isRunning()) {
                if (mActivity != null) {
                    mActivity.getMessageHandler().sendEmptyMessage(DroidDrinViewerConstants.MSG_DISCOVER_START);
                }
            } else {
                /**
                 * If the service is not doing a discovery,
                 * ask him for the most up-to-date host collection
                 * set it in the adapter and display it
                 */
                final DrinHostCollection newCollection = discoverServerApi.getMostUpToDateCollection();
                if (mActivity != null) {
                    mActivity.runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            if (newCollection != null) {
                                getAdapter().setHostCollection(newCollection);
                            } else {
                                getAdapter().initHostCollection();
                            }
                            getAdapter().notifyDataSetChanged();
                        }
                    });
                    /**
                     * either the hostcollection has been set or voided,
                     * turn off the discoverServerProgress
                     */
                    mActivity.getMessageHandler().sendEmptyMessage(DroidDrinViewerConstants.MSG_DISCOVER_DONE);
                }
            }
        } else {
            /**
             * Bind the DiscoverServerService if it is not, note that the onServiceConnected
             * method will send a startdiscovery message to the DrinViewerBroadcastReceiver
             * as soon as the service gets connected at startup
             */
            if (!isBound) {
                Intent intent = new Intent(mActivity.getApplication(), DiscoverServerService.class);
                intent.setAction(DiscoverServerService.class.getName());
                isBound = mActivity.getApplication().bindService(intent, this,
                        Context.BIND_AUTO_CREATE | Context.BIND_NOT_FOREGROUND);
            }
        }
    } catch (RemoteException e) {
        // ignore
        e.printStackTrace();
    }
}