Does adding flags to an intent using a for loop, overwrite the previous flag added in the loop?
Example 1:
What I want to achieve
int[] flags = {Intent.FLAG_ACTIVITY_NEW_TASK, Intent.FLAG_ACTIVITY_CLEAR_TASK};
for (int flag: flags) {
intent.addFlags(flag);
}
Example 2:
How flags are normally added
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
Example 3:
Simple code representation of the for loop in Example 1
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
REASON:
Example 4:
I am passing flags into a method
public void startActivity(int[] flags) {
for (int flag: flags) {
intent.addFlags(flag);
}
}
Resolution:
If a for loop does overwrite the previously added flag, how can I achieve the code seen in Example 2 using the method seen in Example 4?
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…