【发布时间】:2020-02-16 12:04:21
【问题描述】:
我有两个班级,“class1”和“class2”。 当我在“class1”中初始化一个名为“test”(true)的布尔值并在“class2”中的 if 语句中询问它的值时,一切正常。 但是,一旦我在方法中将值从“test1”更改为 false,它就无法识别“class2”中 if 语句的更改。
我的目标是,一旦奖励视频结束,布尔值就会发生变化,并且 class2 中的 if 语句可以识别它。
类1:
public boolean test1= true; //This is recognized by the if-statement in class2
...
@Override
public void onRewardedVideoAdRewarded(Placement placement) {
test1 = false; //this is getting ignored by the if-statement in class2
}
类2:
Class1 class1 = new Class1();
if(class1.test1){
// Do something
}else{
// Do something else
}
希望你能帮助我,谢谢。
【问题讨论】:
-
您正在创建
class1的新实例,然后在调用onRewardedVideoAdRewarded之前检查test1的值。 -
@AndyTurner 我该怎么做才对?
-
@MartinZeitler 你能就我的情况向我解释一下吗?没看懂
-
你怎么知道你的代码在调用
onRewardedVideoAdRewarded?我不认为它到达那里
标签: java android class if-statement boolean