Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

difference between intent.setClass() and intent.setComponent()

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?

like image 484
user860572 Avatar asked Aug 04 '11 12:08

user860572


1 Answers

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*

SetComponent Android Dev

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.

like image 150
sealz Avatar answered Sep 28 '22 20:09

sealz