Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/369.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 启动屏幕在主活动之前不会显示_Java_Android_Xml_Splash Screen - Fatal编程技术网

Java 启动屏幕在主活动之前不会显示

Java 启动屏幕在主活动之前不会显示,java,android,xml,splash-screen,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

我正在开发一个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>

有什么问题吗?

你不应该使用线程, 使用以下命令代替整个线程:

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

}, splashTime);

我猜您没有将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>

如果这是问题所在,请告诉我。

。有些人不鼓励使用闪屏,所以你的闪屏没有任何作用,那么你为什么要使用它呢?我要求帮助它工作,而不是让别人告诉你不要使用它……请发布你的AndroidManifest.xml。@GeoffBolton检查链接。使用处理程序启动屏幕。