Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Black screen before Splash screen appear in android

We know that when the app do some long process like downloading some information from internet it could show a splash screen before loading the application and when the app is loaded completely it will display the main page. In splash screen activity we must load long processes in threads to avoid showing black screen before loading app. I had done all of them. but also the black screen appears before showing app. This is my onCreate method of the splash screen activity:

    protected override void OnCreate (Bundle bundle)     {         try {             base.OnCreate (bundle);             //_dt = DateTime.Now.AddSeconds (_splashTime);             SetContentView (Resource.Layout.Splash );             FirstLoadPB= FindViewById <ProgressBar >(Resource .Id.FirstLoadPB );             FirstLoadingInfo= FindViewById <TextView >(Resource .Id.FirstLoadInfo );             LoadApplication ();          } catch (System.Exception ex) {              Common.HandleException (ex);         }     } 

and this is the code of LoadApplication method:

public void LoadApplication()     {         new System.Threading.Thread (new ThreadStart (() =>                                                       {         //Some Codes to load applications- Downloading from web and accessing the storage(Because was many codes - about 100 line- i was clear them.          }         )                                      ).Start ();     } 

I don't understand why the black screen appears and how should to avoid from this now. I have some code that access to storage in oncreate of my application class. Maybe the issue's root cause be from there.There fore i shared its code:

public override void OnCreate ()     {         try {             base.OnCreate ();             _typeOfShow = new MapViewType ();             ListingTypes = new Dictionary<int,ListingTypeItem> ();              OfflineMode =false;             PropertyShowWasShown = false;             MeasutingUnitsChanged =false;             if(RplXmlSettings .Instance .getVal (AppConstants .XmlSettingShowOnCurrentLocationKey  )== "True")                 typeOfShow .ShowOnCurrentLocation =true ;             else                 typeOfShow .ShowOnCurrentLocation =false;             //StorageClass .ctx = ApplicationContext ;             FillDashboardOnResume =false;             //initlize image loader              ImageLoader = Com.Nostra13.Universalimageloader.Core.ImageLoader.Instance;             Options = new DisplayImageOptions.Builder ()                 .ShowImageForEmptyUri (Resource.Drawable.ic_tab_map)                     .CacheOnDisc ()                     .CacheInMemory ()                     .ImageScaleType (ImageScaleType.InSampleInt)                     .BitmapConfig (Bitmap.Config.Rgb565)                     .Displayer (new FadeInBitmapDisplayer (300))                     .Build ();             ImageLoaderConfiguration config;              ImageLoaderConfiguration .Builder builder =new ImageLoaderConfiguration                 .Builder (ApplicationContext).ThreadPoolSize (3);              if(RplXmlSettings .Instance .getVal (AppConstants .XmlSettingMemoryCacheKey )== "True")                 builder .ThreadPriority (4).MemoryCacheSize (1500000) ;// 1.5 Mb              builder .                 DenyCacheImageMultipleSizesInMemory ().                     DiscCacheFileNameGenerator (new Md5FileNameGenerator ()).                     MemoryCache (new WeakMemoryCache()).                     DiscCacheSize (15000000);             config = builder .Build ();             ImageLoader.Init (config);          } catch (Exception ex) {             Common .HandleException (ex);         }      } 

OK.Long story short.Now the question is this-- Really what is the root cause of this black screen. Is this from splash activity or from application class. And How we can solve it and avoid form showing this?

like image 516
Husein Behboudi Rad Avatar asked Jan 13 '13 19:01

Husein Behboudi Rad


People also ask

How do I show splash screen only in Android?

It is important to check that the first activity which opens when the app is launched is MainActivity. java (The activity which we want to appear only once). For this, open the AndroidManifest. xml file and ensure that we have the intent-filter tag inside the activity tag that should appear just once.

How do I get rid of the default splash screen?

Basically what you've to do is override your splash screen theme in res\values-v31\themes. xml & set a transparent icon. This will get you rid of the default app icon that appears during splash when the app is launch.

What is splash screen in Android initial?

Android Splash Screen is the first screen visible to the user when the application's launched. Splash screen is one of the most vital screens in the application since it's the user's first experience with the application.

How do I get rid of the white screen on my splash screen Android?

On the right in the properties, there is the background attribute. Clicking on this and choosing custom will allow you to define the RGB value you'd like the colour of the white screen to now appear as. Running your app on Android and iOS will now no longer show the annoying white screen.


2 Answers

Add a theme with the background you are using to your application tag in the manifest file to prevent the black screen to be drawn.

theme.xml

<resources> <!-- Base application theme is the default theme. --> <style name="Theme" parent="android:style/Theme" />  <style name="Theme.MyAppTheme" parent="Theme">     <item name="android:windowNoTitle">true</item>     <item name="android:windowContentOverlay">@null</item>     <item name="android:windowBackground">@drawable/my_app_background</item>  </style> </resources> 

AndroidManifest.xml

.... <application         android:name="@string/app_name"         android:icon="@drawable/ic_launcher"         android:label="@string/app_name"         android:theme="@style/Theme.MyAppTheme"          > .... 

Read why there is a black screen here On app launch, Android displays a simple preview window (based on your activity theme) as an immediate response to the user action. Then the preview window crossfades with your actual UI, once that has fully loaded. To ensure a smooth visual transition, your activity theme should match your full UI as closely as possible. The below image shows how the experience can be jarring if not handled properly.

like image 128
TouchBoarder Avatar answered Oct 06 '22 00:10

TouchBoarder


This initial screen that you see is called the "Preview" screen. You can disable this completely by declaring this in your theme:

android:windowDisablePreview  <style name="Theme.MyTheme" parent="android:style/Theme.Holo">     <!-- This disables the black preview screen -->     <item name="android:windowDisablePreview">true</item> </style> 

An explanation of how to handle this screen is posted here: http://cyrilmottier.com/2013/01/23/android-app-launching-made-gorgeous/

like image 24
mdupls Avatar answered Oct 05 '22 22:10

mdupls