在主要活动之前不会显示启动画面

时间:2013-05-26 19:47:43

标签: java android xml splash-screen

我正在开发一个Android应用程序,但似乎无法在主要活动之前启动启动画面,但在我的所有其他应用程序上这已经没问题了

这可能是什么问题?代码没有问题。

package com.example.soundboardapp;



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

public class splash extends Activity {
    private long ms = 0;
    private long splashTime = 2000;
    private boolean splashActive = true;
    private boolean paused = false;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        this.requestWindowFeature(Window.FEATURE_NO_TITLE);

        setContentView(R.layout.splash);

        Thread mythread = new Thread() {
            public void run() {

                try {
                    while (splashActive && ms < splashTime) {
                        if (!paused)
                            ms = ms + 100;
                        sleep(100);
                    }
                } catch (Exception e) {
                } finally {

                    Intent intent = new Intent(splash.this, MainActivity.class);
                    finish();
                    startActivity(intent);
                }
            }
        };
        mythread.start();
    }
}

这是一个与代码对应的启动活动。

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@drawable/intro22"
     >

    <LinearLayout
        android:id="@+id/linearLayout1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:gravity="center" >



    </LinearLayout>

    <ProgressBar
        android:id="@+id/progressBar1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        android:layout_marginBottom="184dp" />

</RelativeLayout>

可能是什么问题?

2 个答案:

答案 0 :(得分:0)

你不应该使用线程, 而不是整个线程,使用此:

new Handler().postDelayed(new Runnable() {
 public void run() {
                    Intent intent = new Intent(splash.this, MainActivity.class);
                    finish();
                    startActivity(intent);

}, splashTime);

答案 1 :(得分:0)

我猜您没有将splash活动设置为应用程序的启动活动。如果您有类似的内容,请查看 AndroidManifest.xml 文件:

<activity android:name="splash" >
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
</activity>

如果那是问题,请告诉我。