安卓客户经理,当用户在菜单中删除帐户时是否有任何回调"Accounts & sync"



我们正在使用Android客户经理来管理帐户。

您知道,用户可以从"帐户&同步"菜单中删除帐户。

用户这样做时是否有回调?(应用不运行)

我们想做一些事情(例如,在用户注销时,将令牌无效,清洁db)。

使用 BroadcastReceiver

public class MyBroadcastReceiver extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {
        final String action = intent.getAction();
        // start the SimlessMainService and set an Action Tag
        Intent yourServiceToHandleThisIntent = new Intent(context, YourServiceToHandleThis.class);
        if ( android.accounts.AccountManager.LOGIN_ACCOUNTS_CHANGED_ACTION.equals(action) ) {
            yourServiceToHandleThisIntent .setAction(Constants.ACTION_LOGIN_ACCOUNTS_CHANGED);
        }
        context.startService(yourServiceToHandleThisIntent );
    }   
}

Manifest.xml

<application>
...
  <receiver
            android:name=".MyBroadcastReceiver "
            android:enabled="true">
            <intent-filter>
                <action android:name="android.accounts.LOGIN_ACCOUNTS_CHANGED" />
            </intent-filter>
        </receiver>
...
</application>

相关内容

最新更新