1

我正在尝试在 android 中为我的应用程序创建启动画面,但它根本不会显示。我使用的代码是 4 个不同的文件。这里是:

飞溅.java

     package com.timchecklist;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;

public class Splash extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        Thread Timer = new Thread() {
            public void run() {

                try {
                    sleep(3000);
                    startActivity(new Intent("com.timchecklist.SPLASHNEW"));

                } catch (InterruptedException e) {
                    e.printStackTrace();
                } finally {
                    finish();
                }
            }
        };
        Timer.start();
    }

}

SplashNew.java

   package com.timchecklist;

import android.app.Activity;
import android.os.Bundle;
import android.view.Window;

public class SplashNew extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.splash);

    }

}

飞溅.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:background="@drawable/pic1"
    android:gravity="center"
    android:orientation="vertical" >

</LinearLayout>

AndroidManifest.xml

  <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.timchecklist"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk android:minSdkVersion="7" />

    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" >
        <activity
            android:name=".TimCheckListActivity"
            android:label="@string/app_name"
            android:theme="@android:style/Theme.NoTitleBar" >
        </activity>
        <activity
            android:name=".SplashNew"
            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>

请告诉我我在这里做错了什么。任何帮助,将不胜感激。多谢你们:)

4

4 回答 4

1

我想Splash should be launcher activity first。以及您SPLASHNEW在 AndroidManifest 文件中声明的位置?

于 2012-06-12T13:20:00.970 回答
0

有更好的方法来制作启动画面。像这样声明一个处理程序,它会在精确的时间后调用下一个要启动的活动:

private Handler splashHandler = new Handler() {

@Override
    public void handleMessage(Message msg) {
        switch (msg.what) {

            Intent intent = new Intent(Splash.this, OtherActivity.class);
            startActivity(intent);
            finish();

            break;
        }
        super.handleMessage(msg);
    }
};

然后在 onCreate 中像这样延迟一段时间后执行代码:

Message msg = new Message();
splashHandler.sendMessageDelayed(msg, SPLASHTIME);
于 2012-06-12T15:14:30.493 回答
0

您应该在 Manifest 文件中添加 SplashNew。

试试下面的代码

 setContentView(R.layout.splash);

 new Thread(new Runnable() {

        public void run() {
                // TODO Auto-generated method stub      
                try {

                    Thread.sleep(2000);
                    startActivity(new Intent(getApplicationContext(),EquipmentCategory.class));
                    finish();

                } catch (InterruptedException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }

            }
        }).start();
于 2012-06-12T13:26:14.757 回答
0

清单文件中没有SplashNew的条目......

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.timchecklist"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk android:minSdkVersion="7" />

<application
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name" >
    <activity
        android:name=".TimCheckListActivity"
        android:label="@string/app_name" >

    </activity>

     <activity
        android:name=".Splash"
        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>

在此处输入图像描述

于 2012-06-12T13:19:49.020 回答