Java – inappbilling activity and completion ()

I'm having a lot of trouble integrating Google's in - App settlement

I have an activity that should be settled in the app I am calling this activity from my main activity using the startActivity method.

Intent i = new Intent();
i.setComponent(new ComponentName("com.mypackage.mainactivity","com.mypackage.mainactivity.InAppBillingActivity"));                
startActivity(i);

And call mbillingservice Requestpurchase ("Android. Test. Purchased", "10") is in the oncreate method of the in app billing activity

public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mHandler = new Handler();
        mInAppBillingPurchaSEObserver = new InAppBillingPurchaSEObserver(mHandler);
        mBillingService = new BillingService();
        mBillingService.setContext(this);

        ResponseHandler.register(mInAppBillingPurchaSEObserver);
        boolean supported = mBillingService.checkBillingSupported();
        System.out.println("onCreate.isBillingSupported " + supported);
        if(supported) {
            Log.i("AJ","Calling requestPurchase");
            mBillingService.requestPurchase("android.test.purchased","10");
        }
    }

Since in app billing makes asynchronous calls to the server, when should I call finish () to return to the main activity But I don't want the activity to end. I still need the result of the asynchronous call So what should I do

After I sent a request to the server, I called finish (). But then I got this exception:

05-29 03:11:58.897: ERROR/ActivityThread(3549): Activity com.mypackage.mainactivity.InAppBillingActivity has leaked ServiceConnection com.mypackage.mainactivity.BillingService@45b0ad50 that was originally bound here
05-29 03:11:58.897: ERROR/ActivityThread(3549): android.app.ServiceConnectionLeaked: Activity com.mypackage.mainactivity.InAppBillingActivity has leaked ServiceConnection com.mypackage.mainactivity.BillingService@45b0ad50 that was originally bound here
05-29 03:11:58.897: ERROR/ActivityThread(3549):     at android.app.ActivityThread$PackageInfo$ServiceDispatcher.(ActivityThread.java:1158)
05-29 03:11:58.897: ERROR/ActivityThread(3549):     at android.app.ActivityThread$PackageInfo.getServiceDispatcher(ActivityThread.java:1053)
05-29 03:11:58.897: ERROR/ActivityThread(3549):     at android.app.ContextImpl.bindService(ContextImpl.java:908)
05-29 03:11:58.897: ERROR/ActivityThread(3549):     at android.content.Contextwrapper.bindService(Contextwrapper.java:347)
05-29 03:11:58.897: ERROR/ActivityThread(3549):     at android.content.Contextwrapper.bindService(Contextwrapper.java:347)
05-29 03:11:58.897: ERROR/ActivityThread(3549):     at com.mypackage.mainactivity.BillingService.bindToMarketBillingService(UnkNown Source)
05-29 03:11:58.897: ERROR/ActivityThread(3549):     at com.mypackage.mainactivity.BillingService.access$000(UnkNown Source)
05-29 03:11:58.897: ERROR/ActivityThread(3549):     at com.mypackage.mainactivity.BillingService$BillingRequest.runRequest(UnkNown Source)
05-29 03:11:58.897: ERROR/ActivityThread(3549):     at com.mypackage.mainactivity.BillingService.checkBillingSupported(UnkNown Source)
05-29 03:11:58.897: ERROR/ActivityThread(3549):     at com.mypackage.mainactivity.InAppBillingActivity.onCreate(UnkNown Source)
05-29 03:11:58.897: ERROR/ActivityThread(3549):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
05-29 03:11:58.897: ERROR/ActivityThread(3549):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2701)
05-29 03:11:58.897: ERROR/ActivityThread(3549):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2753)
05-29 03:11:58.897: ERROR/ActivityThread(3549):     at android.app.ActivityThread.access$2500(ActivityThread.java:129)
05-29 03:11:58.897: ERROR/ActivityThread(3549):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2107)
05-29 03:11:58.897: ERROR/ActivityThread(3549):     at android.os.Handler.dispatchMessage(Handler.java:99)
05-29 03:11:58.897: ERROR/ActivityThread(3549):     at android.os.Looper.loop(Looper.java:143)
05-29 03:11:58.897: ERROR/ActivityThread(3549):     at android.app.ActivityThread.main(ActivityThread.java:4701)
05-29 03:11:58.897: ERROR/ActivityThread(3549):     at java.lang.reflect.Method.invokeNative(Native Method)
05-29 03:11:58.897: ERROR/ActivityThread(3549):     at java.lang.reflect.Method.invoke(Method.java:521)
05-29 03:11:58.897: ERROR/ActivityThread(3549):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
05-29 03:11:58.897: ERROR/ActivityThread(3549):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
05-29 03:11:58.897: ERROR/ActivityThread(3549):     at dalvik.system.NativeStart.main(Native Method)

It did not exit the application, but it stopped inappbillingactivity

Any help would be appreciated

Thank you, Akash

P. S.: my old question, unresolved

Solution

You should use startactivityforresult()

In this way, you can start charging and let it execute asynchronous callback. When it receives "success" or "failure", you can call finish(); Send back the results

Another tutorial on in app billing is simple inApp billing, which provides you with a second perspective and may help you understand what billingservice is trying to achieve

edit

For the error of 'simple inApp Bill': you receive an error when purchasing. You can find the error result in the settlement service. Otherwise, you can update the method in the settlement assistant to stop this operation:

protected static void verifyPurchase(String signedData,String signature) {
            ArrayList<VerifiedPurchase> purchases = BillingSecurity.verifyPurchase(signedData,signature);
            if(purchases != null && !purchases.isEmpty()){ // Check for NPE
                    latestPurchase = purchases.get(0);

                    confirmTransaction(new String[]{latestPurchase.notificationId});
            } else {
                    Log.d(TAG,"BillingHelper.verifyPurchase error. purchases was null");
            }

            if(mCompletedHandler != null){
                    mCompletedHandler.sendEmptyMessage(0);
            } else {
                    Log.e(TAG,"verifyPurchase error. Handler not instantiated. Have you called setCompletedHandler()?");
            }
    }
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>