0

I am new in android, my first app has finished recently. I want to set an IAB (in app billing) in my app,I tested my app and I had the below problems: 1-when I click on the "buy" button eveything is OK and the pay operation run correctly. but when I close the app and click on button I have below errors.

    java.lang.IllegalStateException: Could not execute method of the activity                                                                                

    at android.view.View$1.onClick(View.java:4015)  
at android.view.View.performClick(View.java:4764)
at android.view.View$PerformClick.run(View.java:19844) 
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95) 
at android.os.Looper.loop(Looper.java:135)      
at android.app.ActivityThread.main(ActivityThread.java:5376) 
at java.lang.reflect.Method.invoke(Native Method)    
at java.lang.reflect.Method.invoke(Method.java:372) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:908)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:703)  
Caused by: java.lang.reflect.InvocationTargetException  
at java.lang.reflect.Method.invoke(Native Method) 
at java.lang.reflect.Method.invoke(Method.java:372) 
at android.view.View$1.onClick(View.java:4010)   
at android.view.View.performClick(View.java:4764) 
at android.view.View$PerformClick.run(View.java:19844)    
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)  
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5376)  
at java.lang.reflect.Method.invoke(Native Method)      
at java.lang.reflect.Method.invoke(Method.java:372)   
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:908) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:703)  
Caused by: java.lang.IllegalStateException: Can't start async operation 
(launchPurchaseFlow) because another async operation(refresh inventory) is in progress.      
at 
com.example.android.trivialdrivesample.util.IabHelper.flagStartAsync(IabHelper.java:812)   
at com.example.android.trivialdrivesample.util.IabHelper.launchPurchaseFlow(IabHelper.java:376)                                                                                       at com.example.android.trivialdrivesample.util.IabHelper.launchPurchaseFlow(IabHelper.java:341)                                                                                       at com.example.farshid.columnanalysis.MainActivity.gotoColumnAnalysis(MainActivity.java:186)                                                                                      at java.lang.reflect.Method.invoke(Native Method)                                                                                       at java.lang.reflect.Method.invoke(Method.java:372)                                                                                        at android.view.View$1.onClick(View.java:4010)                                                                                        at android.view.View.performClick(View.java:4764)                                                                                        at android.view.View$PerformClick.run(View.java:19844)                                                                                        at android.os.Handler.handleCallback(Handler.java:739)                                                                                        at android.os.Handler.dispatchMessage(Handler.java:95)                                                                                        at android.os.Looper.loop(Looper.java:135)                                                                                        at android.app.ActivityThread.main(ActivityThread.java:5376)                                                                                        at java.lang.reflect.Method.invoke(Native Method)                                                                                        at java.lang.reflect.Method.invoke(Method.java:372)                                                                                       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:908)                                                                                        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:703) 

2-I have another question :) how can I change my button background when sb buy my app(for example change its test from Buy to Read)

how can I fix them... tnx in advanced.

Lal
  • 14,726
  • 4
  • 45
  • 70
  • "but when I close the app and click on button.." Which button are you clicking if you closed the app? – Gotiasits Aug 29 '17 at 15:56
  • the "buy" button that I clicked before, when I close and open the app again and click the buy button I have those errors. the buy button should be changed its text from "buy" to "Read" but I dont know how! – Farshid Barzegar Aug 29 '17 at 16:05
  • The second part is easy, just call `.setBackground()` on your button object. Also, toggle button would be more convenient, so you don't have to check the state with custom bool. As for the main problem, it is still very unclear... Try overriding onPause(), onDestroy(), onResume()... and use Log.d() to get better picture where is the problem. – Gotiasits Aug 30 '17 at 08:57
  • well... the first problem solved by adding this code if (mHelper != null) mHelper.flagEndAsync(); before calling mHelper.launchPurchaseFlow(this, SKU_PREMIUM, RC_REQUEST, mPurchaseFinishedListener, "payload-string") for the second part, I know .setBackground() changes the backgrounf but how can I find out that user buy my app and after that the button changed its background. – Farshid Barzegar Aug 30 '17 at 13:59
  • Well, that information most certainly cannot be stored (only) locally. You should check this out. https://developer.android.com/google/play/billing/api.html – Gotiasits Aug 30 '17 at 14:12

0 Answers0