Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is difference between "setComponent" and "setClassName" in sending an intent?

From my own Android app, I'm trying to launch an external app's component explicitly.

Intent i = new Intent();
Uri uri = Uri.parse("http://0.0.0.1");
i.setData(uri);
i.setComponent(new ComponentName("other.app.android","other.app.android.Activity1"));
startActivity(i);

Can I replace i.setComponent(...) to i.setClassName("other.app.android", other.app.android.Activity1")? Please let me know what is the difference between them.

like image 479
Youn Kyu Lee Avatar asked Nov 29 '25 15:11

Youn Kyu Lee


1 Answers

Yes, you can do that. Internally setClassName(String, String) creates a new ComponentName(String, String)

public Intent setClassName(String packageName, String className) {
    mComponent = new ComponentName(packageName, className);
    return this;
}
like image 75
sJy Avatar answered Dec 01 '25 06:12

sJy