Java Android故障中的闪屏

Java Android故障中的闪屏,java,android,adt,splash-screen,Java,Android,Adt,Splash Screen,我已经在Android上开发了一个闪屏,持续2秒,然后进入主要活动。问题是,当我启动应用程序时,主活动会持续几毫秒,然后转到启动屏幕活动。我能知道这个问题的解决办法吗 splashscreen.java import android.content.Intent; import android.os.Bundle; import android.os.Handler; import android.view.Window; import android.view.WindowManager;

我已经在Android上开发了一个闪屏,持续2秒,然后进入主要活动。问题是,当我启动应用程序时,主活动会持续几毫秒,然后转到启动屏幕活动。我能知道这个问题的解决办法吗

splashscreen.java

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.view.Window;
import android.view.WindowManager;

public class splashscreen extends Activity {

    private static int splashInterval = 2000;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        etWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);       
       setContentView(R.layout.splashscreen);
       new Handler().postDelayed(new Runnable() {

            @Override
            public void run() {
                // TODO Auto-generated method stub
                Intent i = new Intent(splashscreen.this, MainActivity.class);
                startActivity(i);
                this.finish();
            }

            private void finish() {
                // TODO Auto-generated method stub
            }
        }, 
        splashInterval);
    };
} 
splashscreen.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" >
    <ImageView android:src="@drawable/splash" android:layout_width="fill_parent" android:layout_height="fill_parent" android:scaleType="fitXY"/>

    <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="58dp" />
</RelativeLayout>
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="asdf.splashtest1" >
    <application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" >
        <!-- Splash screen -->
        <activity android:name=".splashscreen" android:label="@string/app_name" android:screenOrientation="portrait" android:noHistory="true" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

        <!-- Main activity -->
        <activity android:name=".MainActivity" android:label="@string/app_name" ></activity>
    </application>
</manifest>      

这是我的启动码也许这会有帮助

Thread Background = new Thread() {
    public void run() {
        try {
            sleep(2000);
            Intent intent = new Intent(splashscreen.this, MainActivity.class);
            startActivity(intent);
            finish();
        } catch (Exception e) {

        }
    };
    Background.start();
}
在sleep(2000)中,以毫秒为单位输入所需的时间

编辑

私有类SplashTask扩展了AsyncTask{
@凌驾
受保护的void onPreExecute(){
}
@凌驾
受保护的Void doInBackground(Void…参数){
试一试{
《睡眠》(2000年);
}捕捉(中断异常e){
e、 printStackTrace();
}
返回null;
}
@凌驾
受保护的void onPostExecute(void结果){
完成();
意向意向=新意向(SplashActivity.this,
主要活动(课堂);
星触觉(意向);
}
}

使用onCreate方法
newsplashtask().execute()调用此异步

问题仍然存在。我解决了。如果您能将您的启动屏幕代码发送给我,我将不胜感激。@UsamaRehan我用新的异步任务编辑代码复制该代码并用您的FillParent修改类已被弃用。.最好添加匹配的Parents请显示第二个活动的代码。@DaniEll我已添加了您的请求。您的代码看起来不错。我猜你的第二项活动有问题。也许它正在自我终结。。。尝试直接启动它(而不是启动屏幕)强制停止应用程序后会发生这种情况吗?
Thread Background = new Thread() {
    public void run() {
        try {
            sleep(2000);
            Intent intent = new Intent(splashscreen.this, MainActivity.class);
            startActivity(intent);
            finish();
        } catch (Exception e) {

        }
    };
    Background.start();
}
 private class SplashTask extends AsyncTask<Void, Void, Void> {
    @Override
    protected void onPreExecute() {

    }

    @Override
    protected Void doInBackground(Void... params) {
        try {
            Thread.sleep(2000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        return null;

    }

    @Override
    protected void onPostExecute(Void result) {
        finish();

        Intent intent = new Intent(SplashActivity.this,
                MainActivity.class);
        startActivity(intent);

    }
}