3

When i launch my app, i see a white screen for couple of seconds before splash screen appears.

I am wondering if the size of my app can affect it ( it is 17.7MB ). Or is it because my testing device is old (HTC Desire HD) and a bit trashed with too much data in it?

Or it is normal behavior? Or maybe problem is in my code, which is below...

Part of the manifest:

    <activity android:name=".SplashView"
          android:noHistory="true"
          android:screenOrientation="portrait"
          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" 
        android:windowSoftInputMode="adjustPan"
        android:configChanges="orientation" >
        <intent-filter >
            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>

Splash activity:

public class SplashView extends SherlockActivity {
private final int SPLASH_DISPLAY_LENGHT = 1000;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    getSupportActionBar().hide();
    setContentView(R.layout.splash_view);
    try {
        RefreshRatingsTask urt = new RefreshRatingsTask();
        urt.execute();
    } catch (Exception e) {
        // ignore
    }
    new Handler().postDelayed(new Runnable() {

        @Override
        public void run() {
            Intent mainIntent = new Intent(SplashView.this,
                    MainActivity.class);
            SplashView.this.startActivity(mainIntent);
            SplashView.this.finish();
        }

    }, SPLASH_DISPLAY_LENGHT);
}
}

thanks

user2224342
  • 75
  • 2
  • 4
  • I think it's a mix of old device + heavy app. That used to happen on my Motorola Spice when I opened Angry Birds on it - white screen for like 20 seconds. – Geeky Guy Jun 19 '13 at 01:18

2 Answers2

9

Android uses the Theme of your initial Activity to show a dummy Activity whilst it loads your application into memory.

Making your app smaller will help reduce the length of the wait and using a Theme to set the style of the splash screen will make it less noticeable.

This blog post by Cyril Mottier has more details.

alex
  • 6,359
  • 1
  • 23
  • 21
0
    RefreshRatingsTask urt = new RefreshRatingsTask();
    urt.execute();

This asynctask seems to be the culprit. Its operation could take time, hence splash screen doesnt appear right away. Comment it out and check again.
Furthermore it is not a good practice to do heavy stuffs on splash activity. Create a service for it and do it in the background.

Lazy Ninja
  • 22,342
  • 9
  • 83
  • 103
  • Thanks for your reply. Btw, RefreshRatingTask extends AsyncTask so it shouldnt be a problem since it runs in the separate thread. But still after commenting it out, same problem.. – user2224342 Jun 19 '13 at 01:22
  • thanks for the feedback. Yeah I knew it is an asynctask. Have you tested it on other devices? Emulator? Is the outcome the same. – Lazy Ninja Jun 19 '13 at 01:28
  • yeah.. same problem on Samsung S3. i guess i have to figure out how to improve speed of the app and reduce its size – user2224342 Jun 21 '13 at 20:32