Reputation: 70
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...:))
Upvotes: 1
Views: 1930
Reputation: 611
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;
}
Upvotes: 2