开发者

Android development: Using intent syntax

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;
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜