user860572
user860572

Reputation: 101

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?

Upvotes: 8

Views: 6855

Answers (1)

sealz
sealz

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*

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.

Upvotes: 2

Related Questions