Issue
By referring to bindService (Intent service, ServiceConnection conn, int flags)
May I know, when should we use 0 for flags
, and when should we should we use BIND_AUTO_CREATE
for flags
? The documentation doesn't explain what is the meaning of 0 for flags.
Example for using 0 as flags
// Start auto complete service.
autoCompleteServiceIntent = new Intent(AutoCompleteService.class.getName());
startService(autoCompleteServiceIntent);
bindService(autoCompleteServiceIntent, serviceConnection, 0);
Example for using BIND_AUTO_CREATE
as flags
mContext.bindService(new Intent("com.android.vending.billing.InAppBillingService.BIND"),
mServiceConn, Context.BIND_AUTO_CREATE);
Solution
For method bindService(Intent, ServiceConnection, flag)
if flag = Context.BIND_AUTO_CREATE
is used it will bind the service
and start the service,
but if "0"
is used, method will return true and will not start service until a call like startService(Intent)
is made to start the service
.
One of the common use of "0"
is in the case where an activity to connect to a local service if that service is running, otherwise you can start the service.
Answered By - Sourab Sharma
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.