0

我正在我的 android 应用程序中制作启动画面,但是如果我尝试在 Run() 中启动一个活动,我会发现应用程序的错误已意外停止,如果我使用 setContentView 而不是 startActivity,也会发生错误,即使我使用 SplashScreen.this.startActivity 而不是只使用 startActivity 我得到错误。我尝试使用 TimerTask 而不是处理程序,但它发生了同样的情况,我做错了什么?

package name.appname;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;

public class SplashScreen extends Activity{
 @Override
    public void onCreate(Bundle savedInstanceState){
        super.onCreate(savedInstanceState);
        setContentView(R.layout.splash);
        Handler handler = new Handler();
        handler.postDelayed(getRunnableStartApp(), 1500);
  }//public void onCreate(Bundle savedInstanceState)

 public Runnable getRunnableStartApp(){
    return new Runnable(){
        public void run(){
            startActivity(new Intent(SplashScreen.this, MainActivity.class));//when i quit this line, no error happens...
            finish();
        }//public void run()
    };//new Runnable()
 }//public Runnable getRunnableStartApp()
}//public class SplashScreen extends Activity

这是清单:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="name.appname"
      android:versionCode="1"
      android:versionName="1.0">
    <application android:allowBackup="false" android:label="@string/app_name">
        <activity android:name="SplashScreen"
                  android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>
</manifest> 

我发现了错误:android.content.ActivityNotFoundException,但不知道为什么会这样

4

2 回答 2

1

Add the below in manifest file. Missing entry for MainActivity

<activity android:name=".MainActivity"
          android:label="@string/app_name">
</activity>

Also change this

<activity android:name="name.appname.SplashScreen"
          android:label="@string/app_name">
<intent-filter>
          <action android:name="android.intent.action.MAIN" />
          <category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

Note: Some people consider using splash screen as evil if it does nothing. Check the below

http://cyrilmottier.com/2012/05/03/splash-screens-are-evil-dont-use-them/

于 2013-06-13T13:45:59.963 回答
0

Use Runnable inside Timertask.
I have also SplashScreen for my app & it works fine.

于 2013-06-13T13:47:05.897 回答