开发者

Android development: Using intent syntax

开发者 https://www.devze.com 2023-03-20 03:50 出处:网络
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:

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

精彩评论

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