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

I study the tutorial and see the author using aim.setClass () to go to the next action, and then on the same page he uses intent.setComponent() to go to the next action.

So what is the difference and what is the advantage of using any of them?

+7
source share
1 answer

In addition to various parameters.

intent.setcomponent() = Explicitly configure the component to handle the intent.

intent.setClass() = Convenience to call setComponent (ComponentName) with the name returned by the class object.

another difference is that .setComponent() can find a suitable class for you.

* From Android Developers *

SetComponent Android Dev

You should set this value only when you know that you absolutely want to use a particular class; otherwise, it’s better to let the system find the appropriate class so that you respect the installed applications and user preferences.

+2
source

All Articles