无法在 Java 中为 Android 应用覆盖 onPurchasesUpdated 方法
onPurchasesUpdated method can't be overridden in Java for Android app
我正在尝试使用应用内结算为 Android 应用编写一个 Java。我使用 this link 作为指南。我已经在初始化计费客户端下添加了他们规定的代码,但我收到一条消息,指出 onPurchasesUpdated 方法没有覆盖其超类中的方法。我怀疑我缺少一个工具,但哪个工具呢?或者这不是问题所在?这是我的代码:
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) {
}
};
}
像这样实现:-
public class ShopActivity extends AppCompatActivity implements PurchasesUpdatedListener{
.
.
.
@Override
public void onPurchasesUpdated(@NonNull BillingResult billingResult, @Nullable List<Purchase> purchases) {
.
.
}
或者你可以这样做 this. This is the recommended way by Google. Also attached is the Google Sample project
我正在尝试使用应用内结算为 Android 应用编写一个 Java。我使用 this link 作为指南。我已经在初始化计费客户端下添加了他们规定的代码,但我收到一条消息,指出 onPurchasesUpdated 方法没有覆盖其超类中的方法。我怀疑我缺少一个工具,但哪个工具呢?或者这不是问题所在?这是我的代码:
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) {
}
};
}
像这样实现:-
public class ShopActivity extends AppCompatActivity implements PurchasesUpdatedListener{
.
.
.
@Override
public void onPurchasesUpdated(@NonNull BillingResult billingResult, @Nullable List<Purchase> purchases) {
.
.
}
或者你可以这样做 this. This is the recommended way by Google. Also attached is the Google Sample project