Reputation: 101
I am looking at a tutorial and see the author using intent.setClass() to get the to the next Activity and then on the same page he uses intent.setComponent()
to get to the next Activity.
So what is the difference and what is the advantage in using any of them?
Upvotes: 8
Views: 6855
Reputation: 5408
Other than different parameters.
intent.setcomponent()
= Explicitly set the component to do the handling of the intent.
intent.setClass()
= Convenience for calling setComponent(ComponentName) with the name returned by a Class object.
another difference is that .setComponent()
can find the appropiate class for you.
*From android Developers*
You should only set this value when you know you absolutely want a specific class to be used; otherwise it is better to let the system find the appropriate class so that you will respect the installed applications and user preferences.
Upvotes: 2