I just started learning android programming and while working through the android Tab Layout tutorial I noticed they created a new Intent with the following code.
// Create an Intent to launch an Activity for the tab (to be reused)
intent = new Intent().setClass(this, ArtistsActivity.class);
Up until now, all the books I’ve read have created a new intent using
intent = new Intent(this, ArtistActivity.class);
and was wondering if there is a difference between the two lines of code.
They are equivalent.
Based on the comment from the tutorial…
It seems they just use the
.setClass()method instead of theConstructorthat takes a class to be more explicit as the Intent item created there will be reused and.setClass()will probably be called on it again.