Android:启动画面后出现黑屏

时间:2013-10-22 11:10:20

标签: java android splash-screen

在我的Android应用程序中,我使用了启动画面。但是在飞溅消失之后,在切换到主要活动之前,下一个屏幕变黑。但我不想黑屏。任何人都可以解释这里发生了什么,我怎么能防止黑屏?这是我的SplashActivity类。

package my.easymedi.controller;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;

public class SplashActivity extends Activity {
private static int SPLASH_TIME_OUT = 3000;

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

    new Handler().postDelayed(new Runnable() {

        @Override
        public void run() {
            Intent i = new Intent(getApplicationContext(),
                    MainActivity.class);
            startActivity(i);
        }
    }, SPLASH_TIME_OUT);
}

}

这是我的清单文件。

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

<uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="17" />

<!-- Permissions -->
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-feature android:name="android.hardware.camera" />
<uses-feature android:name="android.hardware.camera.autofocus" />

<application
    android:allowBackup="true"
    android:icon="@drawable/easy_medi"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name="my.easymedi.controller.SplashActivity"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

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

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

我的日志猫是这样的:

10-22 11:19:59.699: E/Trace(1161): error opening trace file: No such file or directory (2)
10-22 11:19:59.699: W/Trace(1161): Unexpected value from nativeGetEnabledTags: 0
10-22 11:19:59.699: W/Trace(1161): Unexpected value from nativeGetEnabledTags: 0
10-22 11:19:59.699: W/Trace(1161): Unexpected value from nativeGetEnabledTags: 0
10-22 11:20:00.488: W/Trace(1161): Unexpected value from nativeGetEnabledTags: 0
10-22 11:20:00.488: W/Trace(1161): Unexpected value from nativeGetEnabledTags: 0
10-22 11:20:00.968: D/dalvikvm(1161): GC_FOR_ALLOC freed 123K, 9% free 2584K/2824K, paused 44ms, total 47ms
10-22 11:20:01.078: W/Trace(1161): Unexpected value from nativeGetEnabledTags: 0
10-22 11:20:01.078: W/Trace(1161): Unexpected value from nativeGetEnabledTags: 0
10-22 11:20:01.089: W/Trace(1161): Unexpected value from nativeGetEnabledTags: 0
10-22 11:20:01.108: W/Trace(1161): Unexpected value from nativeGetEnabledTags: 0
10-22 11:20:01.178: W/Trace(1161): Unexpected value from nativeGetEnabledTags: 0
10-22 11:20:01.178: W/Trace(1161): Unexpected value from nativeGetEnabledTags: 0
10-22 11:20:01.188: W/Trace(1161): Unexpected value from nativeGetEnabledTags: 0
10-22 11:20:01.279: W/Trace(1161): Unexpected value from nativeGetEnabledTags: 0
10-22 11:20:01.298: W/Trace(1161): Unexpected value from nativeGetEnabledTags: 0
10-22 11:20:01.298: W/Trace(1161): Unexpected value from nativeGetEnabledTags: 0
10-22 11:20:01.298: W/Trace(1161): Unexpected value from nativeGetEnabledTags: 0
10-22 11:20:01.298: W/Trace(1161): Unexpected value from nativeGetEnabledTags: 0
10-22 11:20:01.298: W/Trace(1161): Unexpected value from nativeGetEnabledTags: 0
10-22 11:20:01.328: D/gralloc_goldfish(1161): Emulator without GPU emulation detected.
10-22 11:20:01.389: W/Trace(1161): Unexpected value from nativeGetEnabledTags: 0
10-22 11:20:01.438: W/Trace(1161): Unexpected value from nativeGetEnabledTags: 0
10-22 11:20:04.138: W/Trace(1161): Unexpected value from nativeGetEnabledTags: 0
10-22 11:20:04.198: W/Trace(1161): Unexpected value from nativeGetEnabledTags: 0
10-22 11:20:04.198: W/Trace(1161): Unexpected value from nativeGetEnabledTags: 0
10-22 11:20:04.758: D/dalvikvm(1161): GC_CONCURRENT freed 25K, 6% free 2954K/3116K, paused 73ms+14ms, total 177ms
10-22 11:20:04.758: D/dalvikvm(1161): WAIT_FOR_CONCURRENT_GC blocked 65ms
10-22 11:20:04.878: I/System.out(1161): ===false===
10-22 11:20:05.078: I/System.out(1161): ***copy db***

3 个答案:

答案 0 :(得分:5)

您忘记删除处理程序,请使用此

private final int SPLASH_DISPLAY_TIME = 3000;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.splash);

    final Handler handler = new Handler();

    handler.postDelayed(new Runnable() {
        @Override
        public void run() {
            Intent mainIntent = new Intent(SplashActivity.this,
                    LoginActivity.class);
            SplashActivity.this.startActivity(mainIntent);
            SplashActivity.this.finish();
            handler.removeCallbacks(this);
        }
    }, SPLASH_DISPLAY_TIME);

}

答案 1 :(得分:0)

也许,您可能只想使用简单的Thread代替Handler

private static final long splash_time = 1000;

Thread splashTread = new Thread() {
        @Override
        public void run() {
            try {
                Thread.sleep(splash_time);
            } catch (Exception e) {
                e.printStackTrace();
            } finally {
                Intent main = new Intent(getApplicationContext(),
                        MainActivity.class);
                startActivity(main);
                finish();
            }
        }
    };

然后在你的onCreate中,您可以通过

启动该主题
    splashTread.start();

答案 2 :(得分:0)

  new Thread(new Runnable() {

  @Override
  public void run() {
    try
    {
    Thread.sleep(2000);
    Intent i = new Intent(getApplicationContext(),
                        MainActivity.class);
                startActivity(i);
    }
    catch(Exception e)
    {

    }
   }
    }).start();