George
George

Reputation: 8378

Bind to Service and execute some methods?

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

Answers (2)

NickT
NickT

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

biddulph.r
biddulph.r

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

Related Questions