我有一个很大的问题,我的应用程序需要将近3秒才能开始/打开。在这3秒我只看到一个黑屏。 我知道这个黑屏的一些问题,但他们都不是问题。应用程序需要很长时间才能开始使用黑屏
我运行traceview,我看到onCreate需要超过2秒。比我更深入地看到,TabHost的addTab需要超过2秒。
addTab还调用每个Tab的每个Activity的onCreate? 我也有一个Custom_title_bar,但删除custom_title后它也需要2-3秒。
那么你们有没有想法我能做些什么? 我真的需要每个选项卡中的不同活动,因此,删除活动并使用视图是不可能的。
是否有可能在线程/ AsyncTask中初始化TabBar并在完成后使MainActivity无效?
非常感谢和格尔茨 - 米尔科
编辑:在这里,我加入了一些代码片段,首先什么是发生在我的onCreate在MainActivity:
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
setContentView(R.layout.main_activity);
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.window_title);
Intent intent = new Intent(MainActivity.this, A.class);
setupTab(R.string.tab_a, R.drawable..., intent);
intent = new Intent(MainActivity.this, B.class);
setupTab(R.string.tab_b, R.drawable..., intent);
intent = new Intent(MainActivity.this, C.class);
setupTab(R.string.tab_c, R.drawable..., intent);
intent = new Intent(MainActivity.this, D.class);
setupTab(R.string.tab_d, R.drawable..., intent);
intent = new Intent(MainActivity.this, E.class);
setupTab(R.string.tab_e, R.drawable..., intent);
mTabHost.setCurrentTab(0);
SetupTab:
private void setupTab(int labelRes, int iconRes, Intent intent) {
String tag = (String) getText(labelRes);
mSpec = mTabHost.newTabSpec(tag)
.setIndicator(createTabIndicator(this, tag, iconRes))
.setContent(intent);
mTabHost.addTab(mSpec);
}
private View createTabIndicator(Context context, String title, int icon) {
LinearLayout indicator = (LinearLayout) LayoutInflater.from(context).inflate(R.layout.tab_indicator, null);
TextView label = (TextView) indicator.findViewById(android.R.id.title);
if(title == null) label.setVisibility(View.GONE);
else label.setText(title);
ImageView tabicon = (ImageView) indicator.findViewById(android.R.id.icon);
tabicon.setImageResource(icon);
return indicator;
}
我还为我的应用程序设置了自定义主题。 在traceview中,tabhost.addTab()方法需要超过2000毫秒。也许这就是为什么我看到长时间的黑屏。
有人知道为什么有BlackScreen?我想,当我运行一个普通的不同的应用程序时,没有BlackScreen。我知道如何更改BlackScreen:将主题中的android:background设置为不同的内容,但不能解决时间问题。
我添加了一个SplashScreen,但当应用程序启动时(但只有几毫秒),我也会看到一个黑屏。 SplashScreen是一个带有ImageView和full_screen的无标题活动。它启动一个等待2秒的线程,然后打开MainActivity并自行完成。
感谢。对于这个项目,一个SplashScreen是一个愿望,我已经实现了它。现在黑屏出现,但只有几毫秒。我不确定为什么有Blackscreen。我认为习惯主题是原因。我现在将添加一些代码 – Informatic0re