ComponentName
顾名思义,就是组件名称,通过调用intent.setComponent()方法,我们可以打开另一个应用的Activity或者Service
创建ComponentName 需要两个参数:
(1)第三方应用的包名
(2)要打开的Activity和Service的全名称(包名+类名)
public ComponentName(@NonNull String pkg, @NonNull String cls) {
if (pkg == null) throw new NullPointerException("package name is null");
if (cls == null) throw new NullPointerException("class name is null");
mPackage = pkg;
mClass = cls;
}
启动第三方Acitivity
ComponentName chatActivity =new ComponentName("com.feifei.example", "com.feifei.example.ChatActivity");
Intent intent =new Intent();
intent.setComponent(chatActivity);
startActivity(intent);
启动第三方Service
ComponentName chatService =new ComponentName("com.feifei.example", "c