Reputation: 8378
Ok, I understood, that when you bind to a remote Service
, it won't bind until you return from the callback. I need to bind to a service and execute some method from it immediately. Is there any way? My code looks like:
try {
Parser parser = FrameworkBridge.getFrameworkBridge(this).getParser();
if (parser != null) {
for (Article a : parser.getArticlesList("http://www.bt.dk/mecommobile/latest/news_article/%s/%s?output_type=xml", 1379, 20)) {
listAdapter.add(a);
}
}
} catch (RemoteException e) {
Log.d(TAG, "Service communication failure");
} catch (FrameworkNotInstalledException e) {
Log.d(TAG, "No framework installed. Install it!");
}
Here FrameworkBridge.getFrameworkBridge(this).getParser()
performs all service connection routine and returns remote interface. The problem is -- when I'm in the code above, the connection is not performed yet, therefore parser
is null
. How can I make it connect before exiting the code?
Upvotes: 0
Views: 207
Reputation: 23873
onServiceConnected(..) will tell you when the service is connected and the remote interface is established. Don't try to call any methods in the service until this is triggered.
Upvotes: 0
Reputation: 5266
mContext.bindService( new Intent("name of the class"), this, Context.BIND_AUTO_CREATE);
the above method call on the copy of the context you store should automatically bind the service when you need it. I am not 100% sure, but this should help you out somewhat.
Upvotes: 0