Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
130 views
in Technique[技术] by (71.8m points)

Android:What is difference between setFlags and addFlags for intent

What is difference between setFlags and addFlags for intent. Could any one explain it please. Help Appreciated.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

When you use setFlags you are replacing the old flags... when you use addFlags you are appending new flags. Remember, a flag is just a integer which is power of two... in binary, flags look like this: 1, 10, 100, 1000, etc... (which in this case are 1, 2, 4, 8). So, what addFlags does is appending the integer you pass using the | operator.

// example... 
// value of flags: 1
intent.setFlags(2|4); 
// now flags have this value: 110
intent.addFlags(8); 
// now flags have this value: 1110

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...