开发者

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");
    开发者_Go百科    } 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?


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜