Example usage for android.content Context BIND_IMPORTANT

List of usage examples for android.content Context BIND_IMPORTANT

Introduction

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

Prototype

int BIND_IMPORTANT

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

Click Source Link

Document

Flag for #bindService : this service is very important to the client, so should be brought to the foreground process level when the client is.

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//  w  w  w  . jav  a 2  s  .  c o  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:systems.byteswap.publicstream.MainActivity.java

void createWithoutFragment() {
    Intent mMediaServiceIntent;// w  w  w  . j  av a2  s .co m

    // add the fragment
    dataFragment = new MainFragment();

    mConnection = new ServiceConnection() {
        public void onServiceConnected(ComponentName className, IBinder service) {
            //mService = ((LocalBinder<MediaService>) service).getService();
            mService = MediaService.getService(service);
            dataFragment.setMediaService(mService);
        }

        public void onServiceDisconnected(ComponentName className) {
        }
    };

    dataFragment.setMediaConnection(mConnection);

    //start the mediaplayer service
    mMediaServiceIntent = new Intent(this, MediaService.class);
    startService(mMediaServiceIntent);
    bindService(mMediaServiceIntent, mConnection, Context.BIND_IMPORTANT);
    dataFragment.setMediaServiceIntent(mMediaServiceIntent);
}

From source file:eu.basicairdata.graziano.gpslogger.GPSApplication.java

private void StartAndBindGPSService() {
    GPSServiceIntent = new Intent(GPSApplication.this, GPSService.class);
    //Start the service
    startService(GPSServiceIntent);/*from   w  w  w.  j  av  a 2 s .  co  m*/
    //Bind to the service
    if (Build.VERSION.SDK_INT >= 14)
        bindService(GPSServiceIntent, GPSServiceConnection, Context.BIND_AUTO_CREATE | Context.BIND_IMPORTANT);
    else
        bindService(GPSServiceIntent, GPSServiceConnection, Context.BIND_AUTO_CREATE);
    Log.w("myApp", "[#] GPSApplication.java - StartAndBindGPSService");
}

From source file:org.opensilk.music.playback.control.PlaybackController.java

public void connect() {
    if (mMediaController != null || mWaitingForService) {
        return;//from   ww  w.  j  av a 2 s. c om
    }
    mWaitingForService = true;
    mAppContext.startService(new Intent(mAppContext, PlaybackService.class));
    mAppContext.bindService(new Intent(mAppContext, PlaybackService.class), mServiceConnection,
            Context.BIND_IMPORTANT);
}

From source file:edu.umich.flowfence.service.Sandbox.java

private void bind() {
    onBeforeConnect.fire(this, null);
    int flags = Context.BIND_AUTO_CREATE | Context.BIND_IMPORTANT | Context.BIND_DEBUG_UNBIND;
    if (localLOGD) {
        Log.d(TAG, "binding: " + this);
    }//w  w  w . java 2s  .co m
    String[] packages = new String[s_mKnownPackages.size()];
    packages = s_mKnownPackages.toArray(packages);
    Intent bindIntent = new Intent().setComponent(mComponent).putExtras(s_mExtrasBundle)
            .putExtra(SandboxService.EXTRA_KNOWN_PACKAGES, packages)
            .putExtra(SandboxService.EXTRA_SANDBOX_ID, mID);

    if (!mApplication.bindService(bindIntent, mConnection, flags)) {
        Log.e(TAG, "Couldn't bind to sandbox " + mID);
    }
}

From source file:indrora.atomic.activity.ConversationActivity.java

/**
 * On resume//from ww  w.  ja  va 2 s .c o  m
 */
@Override
public void onResume() {
    // register the receivers as early as possible, otherwise we may loose a
    // broadcast message
    channelReceiver = new ConversationReceiver(server.getId(), this);
    registerReceiver(channelReceiver, new IntentFilter(Broadcast.CONVERSATION_MESSAGE));
    registerReceiver(channelReceiver, new IntentFilter(Broadcast.CONVERSATION_NEW));
    registerReceiver(channelReceiver, new IntentFilter(Broadcast.CONVERSATION_REMOVE));
    registerReceiver(channelReceiver, new IntentFilter(Broadcast.CONVERSATION_TOPIC));

    serverReceiver = new ServerReceiver(this);
    registerReceiver(serverReceiver, new IntentFilter(Broadcast.SERVER_UPDATE));

    super.onResume();

    // Check if speech recognition is enabled and available
    if (new Settings(this).isVoiceRecognitionEnabled()) {
        PackageManager pm = getPackageManager();
        Button speechButton = (Button) findViewById(R.id.speech);
        List<ResolveInfo> activities = pm
                .queryIntentActivities(new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH), 0);

        if (activities.size() != 0) {
            ((Button) findViewById(R.id.speech)).setOnClickListener(new SpeechClickListener(this));
            speechButton.setVisibility(View.VISIBLE);
        }
    }

    // Start service
    Intent intent = new Intent(this, IRCService.class);
    intent.setAction(IRCService.ACTION_FOREGROUND);
    startService(intent);
    int flags = 0;
    if (android.os.Build.VERSION.SDK_INT > 13) {
        flags |= Context.BIND_ABOVE_CLIENT;
        flags |= Context.BIND_IMPORTANT;
    }
    bindService(intent, this, flags);

    // Let's be explicit about this.
    ((EditText) findViewById(R.id.input)).setEnabled(true);

    // Optimization - cache field lookup
    Collection<Conversation> mConversations = server.getConversations();
    MessageListAdapter mAdapter;

    // Fill view with messages that have been buffered while paused
    for (Conversation conversation : mConversations) {
        String name = conversation.getName();
        mAdapter = pagerAdapter.getItemAdapter(name);

        if (mAdapter != null) {
            mAdapter.addBulkMessages(conversation.getBuffer());
            conversation.clearBuffer();
        } else {
            // Was conversation created while we were paused?
            if (pagerAdapter.getPositionByName(name) == -1) {
                onNewConversation(name);
            }
        }

        // Clear new message notifications for the selected conversation
        if (conversation.getStatus() == Conversation.STATUS_SELECTED && conversation.getNewMentions() > 0) {
            Intent ackIntent = new Intent(this, IRCService.class);
            ackIntent.setAction(IRCService.ACTION_ACK_NEW_MENTIONS);
            ackIntent.putExtra(IRCService.EXTRA_ACK_SERVERID, serverId);
            ackIntent.putExtra(IRCService.EXTRA_ACK_CONVTITLE, name);
            startService(ackIntent);
        }
    }

    // Remove views for conversations that ended while we were paused
    int numViews = pagerAdapter.getCount();
    if (numViews > mConversations.size()) {
        for (int i = 0; i < numViews; ++i) {
            if (!mConversations.contains(pagerAdapter.getItem(i))) {
                pagerAdapter.removeConversation(i--);
                --numViews;
            }
        }
    }

    // Join channel that has been selected in JoinActivity
    // (onActivityResult())
    if (joinChannelBuffer != null) {
        new Thread() {
            @Override
            public void run() {
                binder.getService().getConnection(serverId).joinChannel(joinChannelBuffer);
                joinChannelBuffer = null;
            }
        }.start();
    }

    setupColors();
    setupIndicator();

    openSoftKeyboard(findViewById(R.id.input));

    server.setIsForeground(true);
}

From source file:com.smithdtyler.prettygoodmusicplayer.NowPlaying.java

@SuppressLint("InlinedApi")
void doBindService(boolean startService) {
    Log.i(TAG, "Binding to the service!");
    bindService(new Intent(this, MusicPlaybackService.class), mConnection,
            Context.BIND_IMPORTANT | Context.BIND_AUTO_CREATE);
    mIsBound = true;/*from ww w.ja  v a2  s .  com*/
    // Need to start the service so it won't be stopped when this activity is destroyed.
    // https://developer.android.com/guide/components/bound-services.html
    if (startService) {
        startService(new Intent(this, MusicPlaybackService.class));
    }
}

From source file:com.tenforwardconsulting.cordova.BackgroundGeolocationPlugin.java

void doBindService() {
    // Establish a connection with the service.  We use an explicit
    // class name because there is no reason to be able to let other
    // applications replace our component.
    if (!isBound) {
        log.info("Binding to bg service");
        Activity activity = getActivity();
        Intent locationServiceIntent = new Intent(activity, LocationService.class);
        locationServiceIntent.putExtra("config", config);
        activity.bindService(locationServiceIntent, mConnection, Context.BIND_IMPORTANT);
    }//  w  ww . j  a v a 2s . co m
}