[英]How can i check if a Intent was created
I want to check at the beginning of my App if an Intent
exists. 我想检查我的应用程序的开头是否存在
Intent
。 So when I launch it some details are displayed. 因此,当我启动它时,会显示一些详细信息。 I can then switch to a different class to edit those details.
然后,我可以切换到其他班级来编辑这些详细信息。 Now if i switch back to my Main class I want the details to be replaced with the ones I just edited.
现在,如果我切换回我的主类,我希望将这些细节替换为我刚刚编辑的细节。 I hope you guys can help me out and hopefully you understand my question.
我希望你们能帮助我,希望您能理解我的问题。
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_dashboard);
if (getIntent()!= null) {
Intent myintent2 = getIntent();
ArrayList<String> buffer = new ArrayList<>();
buffer = myintent2.getStringArrayListExtra("Interest_items");
for (int f = 0; f < buffer.size(); f++) {
Interests.add(buffer.get(f));
}
} else {
Interests.add("Cycling");
Interests.add("Swimming");
Interests.add ("Running");
}
}
You can use a boolean
. 您可以使用
boolean
。
First define a boolean
as false
above onCreate
part 首先在
onCreate
部分上方将boolean
定义为false
Then change its value to true
in the intent
body 然后在
intent
主体中将其值更改为true
Now you can write an if
control sentence to find that the desired intent
has already executed or not 现在,您可以编写一个
if
控制语句来查找所需的intent
是否已经执行
Another way is correcting your code like this: 另一种方法是像这样更正您的代码:
if (getIntent().getStringArrayListExtra("Interest_items"))!= null)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.