fredlala8 / marketbilling

Automatically exported from code.google.com/p/marketbilling
0 stars 0 forks source link

java.lang.RuntimeException: Unable to destroy activity {x}: java.lang.IllegalArgumentException: Service not registered: x #157

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
STEPS TO REPRODUCE:
1.Create a virtual device with Google API
2. Open activity that uses IabHelper
3. Close activity

ACTUAL OUTPUT:
Crash

NOTES:
To fix the issue:

In startSetup change:

        if (!mContext.getPackageManager().queryIntentServices(serviceIntent, 0).isEmpty()) {
            // service available to handle that Intent
            mContext.bindService(serviceIntent, mServiceConn, Context.BIND_AUTO_CREATE);
            mServiceBound = true;
        }

In dispose change

            if ((mContext != null) && (mServiceBound)) {
                mContext.unbindService(mServiceConn);
                mServiceBound = false;
            }

Add private variable to class
Boolean mServiceBound = false; 

Original issue reported on code.google.com by martinv...@gmail.com on 4 Nov 2013 at 3:21

GoogleCodeExporter commented 8 years ago
This might also work as an fix:
        else {
            // no service available to handle that Intent
            if (listener != null) {
                listener.onIabSetupFinished(
                        new IabResult(BILLING_RESPONSE_RESULT_BILLING_UNAVAILABLE,
                        "Billing service unavailable on device."));
            }
            mServiceConn = null;
        }

Original comment by martinv...@gmail.com on 4 Nov 2013 at 3:56

GoogleCodeExporter commented 8 years ago
I use this way, more robust:

        if (!mContext.getPackageManager().queryIntentServices(serviceIntent, 0).isEmpty()) {
            // service available to handle that Intent
            mServiceBound = mContext.bindService(serviceIntent, mServiceConn, Context.BIND_AUTO_CREATE);
        }

Original comment by huster.z...@gmail.com on 7 Nov 2013 at 5:12