Android布局渲染完成后回调?
如何仅在呈现活动布局后创建/绑定服务?
-- 更新
我在主活动上有两个选项卡(都是单独的活动),选项卡使用的数据来自服务。现在我正在 onCreate
方法中绑定服务。问题是,只有在 onCreate
内的所有语句完成后才会呈现布局。在服务绑定之前会显示空白屏幕
How can i create/bind a service only after activity layout is rendered?
-- Update
I have two tabs (both as separate activities)on the main activity and the data used for tabs comes from Service. Right now i'm binding service inside onCreate
method. Issue is that layout is not rendered till all the statements inside the onCreate
gets finished. A blank screen is shown till the service get bind
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
请参阅 ViewTreeObserver
更多信息:https://stackoverflow.com/a/7735122/338479
See ViewTreeObserver
More info here: https://stackoverflow.com/a/7735122/338479
将创建/绑定服务的调用放在 onCreate 活动的末尾。如果它必须在进程的最后绝对绑定/创建,您可以向您的活动添加一个布尔标志,指示您是否已经绑定或已经创建了服务。然后您可以重写 onResume() ,如下所示:
Put the call to create/bind the service at the end of your onCreate activity. If it must absolutely bind/create at the very end of the process, you can add a boolean flag to your activity indicating whether you are already bound or have already created the service. You could then override onResume() as follows: