`onPurchasesUpdated` 方法无法在 Java 的 Android 应用中被重写。

huangapple go评论102阅读模式
英文:

onPurchasesUpdated method can't be overridden in Java for Android app

问题

我正在尝试编写一个使用应用内购买的 Android Java 应用程序我正在使用[这个链接][1]作为指南我已经根据初始化结算客户端下的说明添加了代码但是我收到一条消息`onPurchasesUpdated` 方法未覆盖其超类的方法我怀疑我漏掉了一个 `implements`,但是应该是哪一个呢或者问题不在这里这是我的代码

    package com.knitcards.myapplication;
    import android.os.Bundle;
    import android.widget.ArrayAdapter;
    import android.widget.ListView;

    import androidx.appcompat.app.AppCompatActivity;

    public class ShopActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_shop);
    }

    private PurchasesUpdatedListener purchasesUpdatedListener = new PurchasesUpdatedListener() {
        @Override
        void onPurchasesUpdated(BillingResult billingResult, List<Purchase> purchases) {

        }
    };

}

  [1]: https://developer.android.com/google/play/billing/integrate
英文:

I'm trying to write a Java for Android app using In-App Billing. I'm using this link as a guide. I've added the code they prescribe under Initialize a Billing Client, but I'm getting a message that the onPurchasesUpdated method does not override the method from its superclass. I suspect that I'm missing an implements, but which one? Or is that not the problem? Here's my code:

package com.knitcards.myapplication;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.ListView;

import androidx.appcompat.app.AppCompatActivity;

public class ShopActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_shop);
}

private PurchasesUpdatedListener purchasesUpdatedListener = new PurchasesUpdatedListener() {
    @Override
    void onPurchasesUpdated(BillingResult billingResult, List&lt;Purchase&gt; purchases) {

    }
};

}

答案1

得分: 1

实现如下所示

public class ShopActivity extends AppCompatActivity implements PurchasesUpdatedListener{
    .
    .
    .
    @Override
    public void onPurchasesUpdated(@NonNull BillingResult billingResult, @Nullable List<Purchase> purchases) {
        .
        .
    }
}

或者您可以像[这样][1]实现这是Google推荐的方法还附上了[Google示例项目][2]

[1]: https://github.com/android/play-billing-samples/blob/master/ClassyTaxiJava/app/src/main/java/com/sample/android/classytaxijava/billing/BillingClientLifecycle.java
[2]: https://github.com/android/play-billing-samples/blob/master/ClassyTaxiJava/
英文:

implement like this:-

public class ShopActivity extends AppCompatActivity implements PurchasesUpdatedListener{
.
.
.
@Override
    public void onPurchasesUpdated(@NonNull BillingResult billingResult, @Nullable List&lt;Purchase&gt; purchases) {
.
.
}

Or you can do like this. This is the recommended way by Google. Also attached is the Google Sample project

huangapple
  • 本文由 发表于 2020年8月22日 04:49:55
  • 转载请务必保留本文链接:https://go.coder-hub.com/63529896.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定