Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android : Black screen is coming after splash screen

In my android app I've used a splash screen. But after splash disappears, then next screen becomes black before switching to main activity. But I don't want black screen. Can anyone please explain what's going on here and how can I prevent that black screen ? This is my SplashActivity class.

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

}

This is my manifest file.

<?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>

My log cat is like this:

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***
like image 937
Rose18 Avatar asked Mar 21 '23 23:03

Rose18


1 Answers

You forgot to remove the handler, use this

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

}
like image 102
Ayman Mahgoub Avatar answered Apr 02 '23 22:04

Ayman Mahgoub