I'm a bit confused on Intents.
Why is
Intent implicit=new Intent(IDownload.class.getName()); an Implicit intent
while
Intent explicit=new Intent(implicit); is an Explicit intent while it doesn't seem to add anything new in its definition. The system doesn't seem to draw any new information that wasn't previously provided by implicit intent above?
In the Android documentation (Intent types),
Explicit intents specify the component to start by name (the fully-qualified class name). You'll typically use an explicit intent to start a component in your own app, because you know the class name of the activity or service you want to start......
Intent implicit=new Intent(IDownload.class.getName()); seems to fulfill this requirement, but is still regarded as an Implicit intent, which as per the documentation:
Implicit intents do not name a specific component, but instead declare a general action to perform, which allows a component from another app to handle it.....
Intent explicit=new Intent(implicit); seems to contradict this, but is still regarded as an Explicit intent.
UPDATE - Sample implementation
ref : Binding to a Service
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setRetainInstance(true); appContext=(Application)getActivity().getApplicationContext(); Intent implicit=new Intent(IDownload.class.getName()); List<ResolveInfo> matches=getActivity().getPackageManager() .queryIntentServices(implicit, 0); if (matches.size() == 0) { Toast.makeText(getActivity(), "Cannot find a matching service!", Toast.LENGTH_LONG).show(); } else if (matches.size() > 1) { Toast.makeText(getActivity(), "Found multiple matching services!", Toast.LENGTH_LONG).show(); } else { ServiceInfo svcInfo=matches.get(0).serviceInfo; try { String otherHash=SignatureUtils.getSignatureHash(getActivity(), svcInfo.applicationInfo.packageName); String expected=getActivity().getString(R.string.expected_sig_hash); if (expected.equals(otherHash)) { Intent explicit=new Intent(implicit); ComponentName cn=new ComponentName(svcInfo.applicationInfo.packageName, svcInfo.name); explicit.setComponent(cn); appContext.bindService(explicit, this, Context.BIND_AUTO_CREATE); } else { Toast.makeText(getActivity(), "Unexpected signature found!", Toast.LENGTH_LONG).show(); } } catch (Exception e) { Log.e(getClass().getSimpleName(), "Exception trying to get signature hash", e); } } }
Intent explicit=new Intent(implicit);is an explicit intent?explicit.setComponent(cn). It is the setting of the component name that makes the intent explicit; he's just naming the variableexplicitbecause in a few lines it will be.