0

Calling back my old question from here

I have problem that my app always load this "initial" screen when user first open my app:

Before load

So after it loads, it load my first screen.

My first screen should be (and, I think, must be) this one.

After load

Here is my AndroidManifest.xml:

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/Theme.Msd"

and below is my Theme.msd(generated from here) :

<style name="Theme.Msd" parent="@android:style/Theme.Holo.Light">
        <item name="android:actionBarItemBackground">@drawable/selectable_background_msd</item>
        <item name="android:popupMenuStyle">@style/PopupMenu.Msd</item>
        <item name="android:dropDownListViewStyle">@style/DropDownListView.Msd</item>
        <item name="android:actionBarTabStyle">@style/ActionBarTabStyle.Msd</item>
        <item name="android:actionDropDownStyle">@style/DropDownNav.Msd</item>
        <item name="android:actionBarStyle">@style/ActionBar.Solid.Msd</item>
        <item name="android:actionModeBackground">@drawable/cab_background_top_msd</item>
        <item name="android:actionModeSplitBackground">@drawable/cab_background_bottom_msd</item>
        <item name="android:actionModeCloseButtonStyle">@style/ActionButton.CloseMode.Msd</item>
Community
  • 1
  • 1
Rendy
  • 5,572
  • 15
  • 52
  • 95

1 Answers1

0

This "initial" screen is the result of Android loading your app. Startup of your app takes its time, especially if you perform a lot of work in the beginning, so you can never completely solve this. There will always be some measure of a delay when starting your app. But there are a few things you can do to improve the situation:

  1. Find the culprit: If this initial white screen is displayed for an unusually long period of time (maybe even seconds) then most likely you are blocking the UI Thread somewhere. Are you implementing a custom Application? If yes then you should know that any work performed in onCreate() will add to that initial startup delay. The same goes for onCreate() in your Activity but the one in your Application is much more important when it comes to startup performance.

  2. Use a transparent Activity: You can mitigate the problem in some measure by making it seem as if your app hasn't started yet. For that purpose you can style your main Activity to be transparent and hide the ActionBar initially. In that case you need to explicitly add a background to the layout of your Activity otherwise it will remain transparent once the loading has finished. You can show the ActionBar again in onCreate() of your Activity or even later in the life cycle if you want. To make an Activity Transparent use a style such as this:

<style name="Transparent" parent="AppTheme">
    <item name="android:windowIsTranslucent">true</item>
    <item name="android:windowBackground">@android:color/transparent</item>
</style>

If you are not using any support ActionBar libraries you can also use Androids default transparent style @android:style/Theme.Translucent.NoTitleBar. Just apply on of those styles to your main Activity like this:

<activity
    android:name=".ui.activities.MainActivity"
    android:theme="@style/Transparent">
    <intent-filter>
        <action android:name="android.intent.action.MAIN"/>
        <category android:name="android.intent.category.LAUNCHER"/>
    </intent-filter>
</activity>
Xaver Kapeller
  • 49,491
  • 11
  • 98
  • 86
  • Hi Xaver, it works perfectly if I change the `windowIsTranslucent`, but I need to add custom animation while loading next activity, since the default animation is gone.. – Rendy Aug 26 '14 at 02:03
  • After some inspections, when I tried to press Home button, the app blinks my phone Home screen, then the app exit. Do you have any advise? – Rendy Aug 26 '14 at 05:41