在其他情况下,意图不起作用 [英] Intent does not work in case of if else
问题描述
这是我的示例代码:
String checkin = imageUpload.getStatus();
if (checkin.equals("1")) {
Toast.makeText(FullImageActivity.this, name+" "+ "Checked In", Toast.LENGTH_LONG).show();
Intent i = new Intent(FullImageActivity.this, MainActivity.class);
startActivity(i);
//openCamera.setText("CheckOut");
} else if (checkin.equals("0")){
Toast.makeText(getApplicationContext(), name + " " + "Checked Out", Toast.LENGTH_LONG).show();
Intent intent = new Intent(getApplicationContext(), MainActivity.class);
startActivity(intent);
}
第一个if可以正常工作,但第二个则不能.第二阶段活动没有变化.请在这里给我个主意.
The first one if is working fine but the second was is not. No activity change in the second stage. Please give me idea here.
推荐答案
除了此处的答案以外,似乎此问题还存在多个问题.正如此处有人指出,以FullImageActivity.this
代替getApplicationContext()
一样,我的假设是它不是正确的rebuild
.因此,对于每个有相同问题的人:在某些设备上(例如,Huawei Ascend mate 7),Android Studio
不会在正确更新后正确安装新版本,尽管它会在Run
选项卡中显示该版本.
In addition to the answers here ,it seems that this issue is by multiple problems. As some here pointed out to take FullImageActivity.this
instead of getApplicationContext()
, my assumption was that it was not rebuild
correctly. So for everybody who has the same problem: On some devices(eg. Huawei Ascend mate 7) , Android Studio
doesn´t install the new version after an update correctly althought it shows this in the Run
tab.
更改某些代码后进行更新的最佳方法是从设备上卸载,清理项目并重新安装您的应用.
因此,此答案不是代码示例(有关上下文的这一部分已经说过了),但很重要并解决了发问者的问题.
So, this answer is not a code example (this part about the context is allready said) but important and fixed the problem of the questioner.
这篇关于在其他情况下,意图不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!