I want to check at the beginning of my App if an Intent
exists. 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
.
First define a boolean
as false
above onCreate
part
Then change its value to true
in the intent
body
Now you can write an if
control sentence to find that the desired intent
has already executed or not
Another way is correcting your code like this:
if (getIntent().getStringArrayListExtra("Interest_items"))!= null)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.