在对Service发送Intent时,
final Intent intent = new Intent(); intent.setAction("com.example.xxh.servertest.TestService2"); .... bindService(intent, conn, Service.BIND_AUTO_CREATE);
或:
Intent intent = new Intent("com.example.xxh.AAA"); Bundle bundle = new Bundle(); bundle.putString("param", "s1"); intent.putExtras(bundle); startService(intent);
报以下错误:
java.lang.RuntimeException: Unable to start activity ComponentInfo {com.example.xxh.servertest/com.example.xxh.servertest.Main3Activity}: java.lang.IllegalArgumentException: Service Intent must be explicit: Intent { act=com.example.xxh.AAA (has extras) }
解决方法:
final Intent intent = new Intent(); intent.setAction("com.example.xxh.servertest.TestService2"); intent.setPackage(getPackageName());