一、在创建Intent实例时,不直接传入需要调用的Activity的名称。而向其传入一个action
Intent intent = new Intent("com.example.helloworld.THIRD_START");
二、被调用的activity注册时需要添加对应的action。注意这里还需要添加至少一个category。
<intent-filter> <action android:name="com.example.helloworld.THIRD_START"/> <category android:name="android.intent.category.DEFAULT"/> </intent-filter>
三、这样就可以启动Intent了。需要注意的是,这里并没有在Intent中添加category。这是因为android.intent.category.DEFAULT是默认被添加的category。
startActivity(intent);
四、如果在intent中添加的category与注册的category不匹配。将会出现异常。
Intent intent = new Intent("com.example.helloworld.THIRD_START");
intent.addCategory("com.example.helloworld.OTHER");
startActivity(intent);
原文:https://www.cnblogs.com/xxie12/p/11469789.html