gpt4 book ai didi

java - Android - 检查某些值不

转载 作者:行者123 更新时间:2023-12-01 15:12:33 25 4
gpt4 key购买 nike

我正在处理 Android 计费并尝试正确设置 onPurchaseStateChange 方法,但它似乎不起作用。

    @Override
public void onPurchaseStateChange(PurchaseState purchaseState, String itemId,
int quantity, long purchaseTime, String developerPayload)
{
if (purchaseState == PurchaseState.PURCHASED)
{
mOwnedItems.add(itemId);

if ( itemId != null && itemId.trim().equals("3") )
{
Intent myIntent = new Intent(ExtraHelpActivity.this, PsychologyActivity.class);
ExtraHelpActivity.this.startActivity(myIntent);
}
if ( itemId != null && itemId.trim().equals("4") )
{
Intent myIntent = new Intent(ExtraHelpActivity.this, NumberOfBusinessesActivity.class);
ExtraHelpActivity.this.startActivity(myIntent);
}
}
else
if (purchaseState == PurchaseState.CANCELED)
{
// purchase canceled
}
else
if (purchaseState == PurchaseState.REFUNDED)
{
// user ask for a refund
}
else
{
if ( itemId != null && itemId.equals("3") )
{
Intent myIntent = new Intent(ExtraHelpActivity.this, PsychologyActivity.class);
ExtraHelpActivity.this.startActivity(myIntent);
}
if ( itemId != null && itemId.equals("4") )
{
Intent myIntent = new Intent(ExtraHelpActivity.this, NumberOfBusinessesActivity.class);
ExtraHelpActivity.this.startActivity(myIntent);
}
}

因此,当purchaseId为“4”或“3”并且purchaseState==PurchaseState.PURCHASED ....出于某种原因,它似乎没有进入该if语句,并且没有执行去的 Intent 下一页?

有人知道为什么会发生这种情况吗?看起来很奇怪。这可能是 Java 的事情吗?

谢谢!

最佳答案

PurchaseState 不是像 intlongfloat 等原始数据类型,因此您应该使用:

purchaseState.equals(PurchaseState.PURCHASED)

而不是 ==,就像使用字符串一样:

string1.equals(string2) // Results you expect

不等于

string1 == string2 // Don't do this...

关于java - Android - 检查某些值不,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12134079/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com