我是Android应用程序开发的新手。当从设置中清除应用程序数据时,我的启动画面需要19秒才能加载。 当App启动Splash Screen需要5秒。我不知道为什么需要时间 下面是我的android AndroidManifest文件代码:
<activity android:name=".activity.SplashActivity"
android:screenOrientation="portrait"
android:theme="@style/SplashTheme"
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
我的启动活动如下
public class SplashActivity extends AppCompatActivity {
public final int SPLASH_DISPLAY_LENGTH=1000;
@Override
protected void onCreate(Bundle savedInstanceState) {
setTheme(R.style.SplashTheme);
super.onCreate(savedInstanceState);
// setContentView(R.layout.activity_splash);
new Handler().postDelayed(new Runnable(){
@Override
public void run() {
/* Create an Intent that will start the Menu-Activity. */
Intent mainIntent = new Intent(SplashActivity.this,MainActivity.class);
startActivity(mainIntent);
finish();
}
}, SPLASH_DISPLAY_LENGTH);
}
}
我的Splash主题如下:
<style name="SplashTheme" parent="Theme.AppCompat.NoActionBar">
<item name="android:windowDisablePreview">true</item>
<item name="android:windowBackground">@drawable/splash_screen_drawable</item>
</style>
我的Splash屏幕可绘制如下:
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:drawable="@color/icons"
/>
<item
android:left="65dp"
android:right="65dp">
<bitmap
android:gravity="center"
android:src="@drawable/placeholder_splash"
/>
</item>
<item android:drawable="@android:color/transparent"></item>
</layer-list>
答案 0 :(得分:0)
public class SplashActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setTheme(R.style.SplashTheme);
Thread th = new Thread() {
@Override
public void run() {
try {
sleep(1000);
Intent i = new Intent(getBaseContext(), MainActivity.class);
startActivity(i);
finish();
} catch (Exception e) {
}
}
};
th.start();
}
}
答案 1 :(得分:0)