Tag Archives: Service Intent must be explicit

Service Intent must be explicit solution: continued

Call the setAction and setPackage methods at the same time when the intent is in life, so that the created intent is explicit

final Intent intent = new Intent();
intent.setAction("com.example.user.firstapp.FIRST_SERVICE");
intent.setPackage(this.getPackageName());
bindService(intent,conn,Service.BIND_AUTO_CREATE);

That is, after the action of the intent is set, the package name of the service must be set. This is a local call, so the package name can be obtained with the getPackageName() method.