4

在我的 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***
4

3 回答 3

7

你忘了删除处理程序,使用这个

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);

}
于 2013-10-22T11:28:36.953 回答
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();
于 2013-10-22T11:21:03.297 回答
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();
于 2013-10-22T11:28:44.907 回答