Closed cristiandaulisio closed 6 years ago
It is only for the Android project, you need to setup the Init in your Android app
CrossCurrentActivity.Current.Init(this); I wrote it in Android application. Is it possible that it is not accessible from pcl project?
That is what needs to be in your Android application or activity yes it is not accessible from anything but Android projects
if you are using 2.0 of current activity plugin you must use the beta version of this plugin.
I'm just updated at 2.0.0, but still not work.. i simply add:
CrossCurrentActivity.Current.Init(this); in Application
but
CrossCurrentActivity.Current.Activity is always null
and i receive this exception:
Current Context/Activity is null, ensure that the MainApplication.cs file is setting the CurrentActivity in your source code so the In App Billing can use it.
Now i am in Android project.
can you try version 2.0 as it is compiled against this dependency.
I am using CurrentActivity 2.1.0.2 and InappBilling 2.0.0
Still getting the same thing? Try putting it in the main activity perhaps.
I tried and nothing.. don't know if it is normal but if i check in debug mode i see that Activity is always null: https://i.imgur.com/VdT7JYw.png
Another info is that i am using MvvmCross framework.
When and where are you calling: PurchaseAsync ? I havent' had any problems with this at all.
It wont be filled in until a lifecycle event happens so adding a breakpoint there should be null
I create a class inside the android project that i call from mainactivity.
I call first:
var purchase = await _billingObject.PurchaseAsync(productId, ItemType.InAppPurchase, _payload);
and work fine.
After i call:
var consuption = await _billingObject.ConsumePurchaseAsync(purchase.ProductId, purchase.PurchaseToken);
and here it throw that exception.
In the OnCreate?
I don't set it yet, so it would be null..
Try the 2.1.0.4-beta of current activity as I refactored it a bit.
I'm calling from NavigationMenu, but i will try 2.1.0.4 when it is available on nuget
Just tried..nothing changed with 2.1.0.4 beta
What can i do to help you? can i debug something?
Another info for you is that if i call: var consuption = await _billingObject.ConsumePurchaseAsync(purchase.ProductId, purchase.PurchaseToken);
after purchaseasync it throw exception but if i call it direclty it work and consume.
update: i downgraded currentactivity at version 1.0.1 and now it work! Something wrong in 2.x?
I have exactly the same issue. After the call to Init(app, bundle), the activity is null. Downgrading to 1.01 also fixed the issue (and I set the activity manually using (Android.App.Activity)Forms.Context;
If you are creating an issue for a BUG please fill out this information. If you are asking a question or requesting a feature you can delete the sections below.
Failure to fill out this information will result in this issue being closed. If you post a full stack trace in a bug it will be closed, please post it to http://gist.github.com and then post the link here.
Bug Information
Version Number of Plugin: 1.4.1 Device Tested On: Nexus5 Simulator Tested On: Version of VS: 15.7.1 Version of Xamarin: 4.10.0.442 Versions of other things you are using:
Steps to reproduce the Behavior
Create a pcl project and an Android project. Write Inappbilling functions in pcl project and call from android project
Expected Behavior
Actual Behavior
All work fine, except when i try to buy and consume an item: PurchaseAsync(productId, ItemType.InAppPurchase, _payload); ConsumePurchaseAsync(purchase.ProductId, purchase.PurchaseToken);
When i call ConsumePurchaseAsync(purchase.ProductId, purchase.PurchaseToken); it throw an exception that currentActivity is null. I tried to init currentactivity in Application and Activity without success.
Code snippet
Screenshotst