我们知道,可以通过隐式Intent来跨应用启动Activity,通过配置
intent-filter中的Action:
startActivity(new Intent("aty_B"));
对于跨应用启动Service的情况,Android 5.0之后就不允许通过隐式启动了。
serviceIntent = new Intent();
serviceIntent.setComponent(new ComponentName("com.jackie.startanotherapp", "com.jackie.startanotherapp.AppService"));
startService(serviceIntent);
这里指定了包名,类名,因此是一个显式启动,合符要求。
启动/停止anotherApp中的按钮,主意Logcat要切换到包含Service的那个app,
10-20 22:17:46.231 26358-26358/com.jackie.startanotherapp V/jackie: Service created
10-20 22:17:50.376 26358-26358/com.jackie.startanotherapp V/jackie: Service destroyed