Context unregisterReceiver - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Context unregisterReceiver method.

This code example shows how to use the following methods:unregisterReceiver
    public void registerIntent() { 
        mContext.registerReceiver(this, mFilter);
    } 
 
    public void unregisterIntent() { 
        mContext.unregisterReceiver(this);
    } 
 
    @Override 
    public void onReceive(Context context, Intent intent) {
        String action = intent.getAction();
 
        try { 
            if (TelephonyIntents.ACTION_SIGNAL_STRENGTH_CHANGED.equals(action)) {
                mSignalStrength = SignalStrength.newFromBundle(intent.getExtras());
 
                if (mTarget != null && getNotifySignalStrength()) {
                    Message message = Message.obtain(mTarget, mAsuEventWhat);
                    mTarget.sendMessage(message);
                } 
7
CodeRank
This code example shows how to use the following methods:unregisterReceiver
  protected void finishConnectivity() { 
    Log.w("MmsService", "Calling stop using network feature!");
    connectivityManager.stopUsingNetworkFeature(ConnectivityManager.TYPE_MOBILE, FEATURE_ENABLE_MMS);
 
    if (connectivityListener != null) {
      context.unregisterReceiver(connectivityListener);
      connectivityListener = null;
    } 
 
    if (this.wakeLock.isHeld())
      this.wakeLock.release();
  } 
 
  private void issueConnectivityChange() { 
    Intent intent = new Intent(context, SendReceiveService.class);
    intent.setAction(getConnectivityAction());
    context.startService(intent);
  } 
 
  private class ConnectivityListener extends BroadcastReceiver {
7
CodeRank
This code example shows how to use the following methods:unregisterReceiver
     
    public void unregister() { 
        if (mRegisteredContext == null) {
            throw new IllegalStateException("Not registered");
        } 
        mRegisteredContext.unregisterReceiver(this);
        mRegisteredContext = null;
    } 
     
    //not yet implemented 
    boolean isPackageUpdating(String packageName) {
        synchronized (mUpdatingPackages) {
            return mUpdatingPackages.contains(packageName);
        } 
    } 
     
    public void onBeginPackageChanges() { 
    } 
     
    public void onPackageAdded(String packageName, int uid) {
7
CodeRank
This code example shows how to use the following methods:unregisterReceiver
	public void onReceive( Context context, Intent intent ) { }
	 
	public void unregister( ) { 
		if( mRegistered && mContext != null )
		{ 
			mContext.unregisterReceiver( this );
			mRegistered = false;
			mContext    = null;
		} 
	} 
	 
	public void register( Context context ) {
		if( mRegistered )
			unregister( ); 
		 
		context.registerReceiver( this, getFilter() );
		mRegistered = true;
		mContext    = context;
	} 
	 
6
CodeRank
This code example shows how to use the following methods:unregisterReceiver
        mContext.registerReceiver(mReceiver, mIntentFilter);
        mCheckbox.setOnPreferenceChangeListener(this);
    } 
 
    public void pause() { 
        mContext.unregisterReceiver(mReceiver);
        mCheckbox.setOnPreferenceChangeListener(null);
    } 
 
    public boolean onPreferenceChange(Preference preference, Object value) {
 
        final boolean desiredState = (Boolean) value;
        mCheckbox.setEnabled(false);
        mNsdManager.setEnabled(desiredState);
        return false; 
    } 
 
    private void handleNsdStateChanged(int newState) {
        switch (newState) {
            case NsdManager.NSD_STATE_DISABLED:
6
CodeRank
This code example shows how to use the following methods:unregisterReceiver
        } 
    } 
 
    public synchronized void stop() { 
        if (mIsEnabled) {
            mApplicationContext.unregisterReceiver(this);
            mIsEnabled = false;
        } 
    } 
 
    @Override 
    public void onReceive(Context context, Intent intent) {
        if (!intent.getAction().equals(Intent.ACTION_BATTERY_CHANGED)) {
            Log.e(LOGTAG, "Got an unexpected intent!");
            return; 
        } 
 
        boolean previousCharging = isCharging();
        double previousLevel = getLevel();
 
6
CodeRank
This code example shows how to use the following methods:unregisterReceiver
 
    @Override 
    protected void onDetachedFromWindow() { 
        super.onDetachedFromWindow(); 
        if (mAttached) {
            mContext.unregisterReceiver(weatherReceiver);
            mAttached = false;
        } 
    } 
 
    public void updateWeather(Intent intent) {
        String wText = (mShowLocation) ? (intent.getCharSequenceExtra(EXTRA_CITY) + ", " + intent.getCharSequenceExtra(EXTRA_TEMP) + ", "
                + intent.getCharSequenceExtra(EXTRA_CONDITION)) : (intent.getCharSequenceExtra(EXTRA_TEMP) + ", "
                        + intent.getCharSequenceExtra(EXTRA_CONDITION));
        this.setText(wText);
    } 
} 
6
CodeRank
This code example shows how to use the following methods:unregisterReceiver
 
		@Override 
		public void onReceive(Context context, Intent intent) {
			if (getResultCode() != Activity.RESULT_OK) {
				mRecvRetVal = false;
				context.unregisterReceiver(this);
				mSem.release();
				return; 
			} 
 
			// Fix for a potential null object here 
			if (mPendingIntents != null) {
				mPendingIntents.remove(mPendingIntents.size() - 1);
				if (mPendingIntents.isEmpty()) {
					mRecvRetVal = true;
					context.unregisterReceiver(this);
					mSem.release();
				} 
			} 
		} 
 
6
CodeRank
This code example shows how to use the following methods:unregisterReceiver
                .setMessage(R.string.dialog_test_message) 
                .setPositiveButton(R.string.dialog_test_button, new DialogInterface.OnClickListener() {
                    @Override 
                    public void onClick(DialogInterface dialog, int which) {
                        if (mReceiver != null) {
                            context.unregisterReceiver(mReceiver);
                            mReceiver = null;
                        } 
                    } 
                }) 
                .create(); 
 
        mTestDialog.show();
    } 
 
    /** 
     * Getters and Setters 
     */ 
 
    public int getColor() { 
6
CodeRank
This code example shows how to use the following methods:unregisterReceiver
        context.registerReceiver(this, filter);
 
    } 
 
    public void release() { 
        mContext.unregisterReceiver(this);
    } 
 
    public void onCheckedChanged(CompoundButton view, boolean checked) {
        if (checked != mAirplaneMode) {
            mAirplaneMode = checked;
            unsafe(checked);
        } 
    } 
 
    public void onReceive(Context context, Intent intent) {
        if (Intent.ACTION_AIRPLANE_MODE_CHANGED.equals(intent.getAction())) {
            final boolean enabled = intent.getBooleanExtra("state", false);
            if (enabled != mAirplaneMode) {
                mAirplaneMode = enabled;
6
CodeRank

Related Context unregisterReceiver Questions & Answers:

unregisterReceiver Method Overview
Unregister a previously registered BroadcastReceiver.
See Code Examples for other Android Context Methods: