我已经在 SO 上查找了类似的帖子。我添加了 splash.java 类、splash_layout.xml 文件,
我有 2 个应用程序图标出现在桌面模拟器上,并且启动画面在那里,但是 2 个图标不好 我怀疑它是关于清单的,我应该在其中作为 android.MAIN、android.DEFAULT 放什么?
这是我的 android manifest.xml 文件:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.kaban.it_ebooksinfomobile" >
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:icon="@drawable/logo"
android:label="@string/app_name"
android:theme="@style/Theme.Book">
<something must be here for splash screen before MainActivity...>
<activity
android:name=".MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
这是启动 java 文件:
package com.example.kaban.it_ebooksinfomobile;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
public class SplashScreen extends Activity {
private final int SPLASH_DISPLAY_LENGTH = 1000;
private static boolean splashLoaded = false;
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
if(!splashLoaded){
setContentView(R.layout.splashscreen);
splashLoaded = true ;
/* New Handler to start the Menu-Activity
* and close this Splash-Screen after some seconds.*/
new Handler().postDelayed(new Runnable(){
@Override
public void run() {
/* Create an Intent that will start the Menu-Activity. */
startActivity(new Intent(SplashScreen.this, MainActivity.class));
finish();
}
}, SPLASH_DISPLAY_LENGTH);
}
else {
Intent goToMainActivity = new Intent(SplashScreen.this, MainActivity.class);
goToMainActivity.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
startActivity(goToMainActivity);
finish();
}
}
}
但它仍然没有加载我的飞溅!它曾经加载,但在虚拟模拟器桌面上有 2 个应用程序图标,这很愚蠢。我认为将 .SplashActivity 作为启动器是不对的,我已经这样做了:
<activity
android:name=".HomeScreen"
android:label="@string/app_name" >>
</activity>
<activity
android:name=".Splash"
android:label="@string/title_activity_splash_screen" >>
<intent-filter>
<action android:name="android.intent.action.MAIN" />>
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
< /activity>