我有一个 android 服务需要很长时间来初始化。我想通过在初始化时显示启动画面来隐藏它。请注意服务的初始化和启动画面的显示是同时发生的,当初始化结束时, Activity 返回到正常布局。所以请不要建议有一个独立的启动画面显示一段时间然后开始我的主要 Activity 。该服务在主要 Activity 中初始化,因此启动画面也必须在主要 Activity 中完成。
最佳答案
你应该使用 Fragment为了那个原因。当您能够在 fragment View 中显示启动画面时,您将处于主要 Activity 上下文中。
来自该附加链接的示例:
For example, here's a subclass of Fragment that loads a layout from the example_fragment.xml file:
public static class ExampleFragment extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.example_fragment, container, false);
}
}
在问我更多问题之前,请阅读完整的文章。
关于android - 如何在初始化 android 服务时加载不同的布局,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20855028/