I'm learning Java and playing around with Android samples in Eclipse. I've come across code from two different sources and would like to know the difference between the following:
Intent intent = new Intent(this, SomeActivity.class);
---AND---
Intent intent = new Intent().setClass(this, SomeActivity.class);
Thanks!
开发者_开发技巧(All these objects make me feel like I'm building a puzzle rather than coding. Not having much fun here...:))
In the first case you create the Intent
with the class data. In the second case you create an empty Intent
and set the class data after. The result is the same, according to the android source code.
The constructor:
public Intent(Context packageContext, Class<?> cls) {
mComponent = new ComponentName(packageContext, cls);
}
The setClass
method:
public Intent setClass(Context packageContext, Class<?> cls) {
mComponent = new ComponentName(packageContext, cls);
return this;
}
精彩评论