However, whenever I connect to *unregister* my app, the onServiceConnected callback gets called twice. Once when I connect so that I can unregister, and once after I've disconnected (and nulled out my reference to) the ReceiptRegistrationConnector object.
I've checked to make sure it's the same ReceiptRegistrationConnector whose onServiceConnected is getting called, and it is.
Is there something obvious I'm missing? Applicable code below (see THIS BIT GETS CALLED AFTER DISCONNECT).
// Receipt notification setup and teardown public static void ensureReceiptNotifications(Context context) { connectAccount(context); receiptConnector = new ReceiptRegistrationConnector(context, account, new ServiceConnector.OnServiceConnectedListener() { @Override public void onServiceConnected(ServiceConnector<? extends IInterface> serviceConnector) { registerAsReceiptListener(); } @Override public void onServiceDisconnected(ServiceConnector<? extends IInterface> serviceConnector) { } }); receiptConnector.connect(); } public static void stopReceiptNotifications(Context context) { connectAccount(context); receiptConnector = new ReceiptRegistrationConnector(context, account, new ServiceConnector.OnServiceConnectedListener() { @Override public void onServiceConnected(ServiceConnector<? extends IInterface> serviceConnector) { // THIS BIT GETS CALLED AFTER DISCONNECT() unregisterAsReceiptListener(); } @Override public void onServiceDisconnected(ServiceConnector<? extends IInterface> serviceConnector) { } }); receiptConnector.connect(); } private static void connectAccount(Context context) { if (account == null) { account = CloverAccount.getAccount(context); } } private static void registerAsReceiptListener() { new AsyncTask<Void, Void, Void>() { @Override protected Void doInBackground(Void... params) { receiptConnector.register(Uri.parse(ReceiptContentProvider.CONTENT_DIRECTORY_URI.toString()), new ReceiptRegistrationConnector.ReceiptRegistrationCallback<Void>()); return null; } @Override protected void onPostExecute(Void result) { super.onPostExecute(result); receiptConnector.disconnect(); receiptConnector = null; } }.execute(); } private static void unregisterAsReceiptListener() { new AsyncTask<Void, Void, Void>() { @Override protected Void doInBackground(Void... params) { receiptConnector.unregister(Uri.parse(ReceiptContentProvider.CONTENT_DIRECTORY_URI.toString()), new ReceiptRegistrationConnector.ReceiptRegistrationCallback<Void>()); return null; } @Override protected void onPostExecute(Void result) { super.onPostExecute(result); receiptConnector.disconnect(); receiptConnector = null; } }.execute();