1

I have the following splash screen defined (splash.xml):

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"
    android:opacity="opaque">
  <item android:drawable="@color/colorGold"/>
  <item>
    <bitmap
        android:gravity="center"
        android:src="@drawable/Banner2"/>
  </item>
</layer-list>

This is the style.xml:

<resources>

    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
    </style>

    <style name="AppTheme.NoActionBar">
        <item name="windowActionBar">false</item>
        <item name="windowNoTitle">false</item>
    </style>

    <style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />

    <style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />

    <style name ="Theme.AppCompat.Light.NoActionBar" parent="ThemeOverlay.AppCompat"/>

    <style name="SplashTheme" parent="AppTheme">
      <item name="android:windowBackground">@drawable/splash</item>
    </style>
</resources>

This is my manifest:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="1" android:versionName="1.0" package="OML_Android.OML_Android" android:installLocation="auto">
    <uses-sdk android:minSdkVersion="10" android:targetSdkVersion="28" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
    <uses-permission android:name="android.permission.BIND_NOTIFICATION_LISTENER_SERVICE" />
    <service android:name=".SignalRSrv" android:label="Messenger" android:enabled="true"></service>
    <application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:theme="@style/AppTheme">
  <activity android:name=".activities.MainActivity"
    android:theme="@style/SplashTheme">
    <intent-filter>
      <action android:name="android.intent.action.MAIN" />
      <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
  </activity>
  </application>
</manifest>

The splash screen does not display at all, nothing. I copied the splash screen xml from a post here on stackoverflow and I've been at this for a couple of days now and have made zero progress. What am I missing?

* Update *

Made progress thanks to @Dipankar Baghel now get the splash screen, but the app crashes with unhandled exception, my activity code is:

using System;
using Android.App;
using Android.OS;
using Android.Runtime;
using Android.Support.Design.Widget;
using Android.Support.V7.App;
using Android.Views;
using Android.Widget;
using Android.Content;
using Acr.UserDialogs;

namespace MyAndroidApp
{
    [Activity(Label = "@string/app_name", Theme = "@style/AppTheme.NoActionBar", MainLauncher = true, NoHistory = true)]
    public class MainActivity : Activity
    {

        protected override void OnCreate(Bundle savedInstanceState)
        {
            // reset theme prior to loading layout
            SetTheme(Resource.Style.AppTheme);
            base.OnCreate(savedInstanceState);
            SetContentView(Resource.Layout.activity_main);
            RequestedOrientation = Android.Content.PM.ScreenOrientation.Portrait;


            Android.Widget.Button MyButton = FindViewById<Android.Widget.Button>(Resource.Id.button_ok);

            UserDialogs.Init(this);

            MyButton.Click += (sender, e) =>
             {
                 Context context = this.ApplicationContext;
                 Intent intent = new Intent(this, typeof(Logon));
                 intent.SetFlags(ActivityFlags.NewTask);
                 StartActivity(intent);
                 Finish();
             };
        }
    }
}

This is the layout code:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <ImageView
        android:src="@drawable/Banner2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/imageView1" />

    <Button
        android:text="Ok"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/button_ok" />


</LinearLayout>

There's not much to the layout, but the error I'm getting is:

`Unable to instantiate activity ComponentInfo{MyAndroid.MyAndroid/MyAndroid.MyAndroid.activities.activity_main}:``

* Update *

Updated manifest code.

Prescott Chartier
  • 1,519
  • 3
  • 17
  • 34
  • Comments are not for extended discussion; this conversation has been [moved to chat](https://chat.stackoverflow.com/rooms/209080/discussion-on-question-by-prescott-chartier-android-splash-screen-doesnt-displa). – Samuel Liew Mar 05 '20 at 12:09

2 Answers2

0

layer-list is not a valid container in Activity xml. please replace with any layout container like LinearLayout,RelativeLayout and it should work.

Secondly Activity tag should be inside Application tag in menifest file like below -

Example -

<application>
  <activity></activity>
</application>

Your code should be look like below -

<application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:theme="@style/AppTheme">
  <activity android:name=".activities.MainActivity"
    android:theme="@style/SplashTheme">
    <intent-filter>
      <action android:name="android.intent.action.MAIN" />
      <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
  </activity>
</application>
</manifest>
Dipankar Baghel
  • 1,932
  • 2
  • 12
  • 24
  • No errors, exactly the same result as `layer-list`, nothing. – Prescott Chartier Mar 04 '20 at 03:36
  • Oh I got your issue you have placed Activity outside application tag it should be inside application I have updated the answer please check – Dipankar Baghel Mar 04 '20 at 03:43
  • Ok, put the code inside the application tag and the app crashed saying it couldn't find `MainActivity`, that's because my layout is called `activity_main`, changed the code in the manifest and the app crashed again. I swapped out the `LinearLayout` code for the original `layer-list`code and I got the splash screen, but the app crashed. No error message, just an `unhandled exception` message. But made progress. – Prescott Chartier Mar 04 '20 at 04:10
  • @PrescottChartier could you share me your Activity class code. – Dipankar Baghel Mar 04 '20 at 04:12
  • Please add a Button with id button_ok in your activity xml file. – Dipankar Baghel Mar 04 '20 at 04:21
0

I think you have a misunderstanding here.

The "android:windowBackground" you had in SplashTheme is actualy not Android Splash screen. It is just a window will be displayed immediately after you launch your Application. This window will be displayed until the main Activity of application started.

Normally, you can see this windowBackground for the first time you launch your application (Cold start). But if you resume or Hot start application after Cold start you may not see the windowBackground.

For more detail please refer below link

https://developer.android.com/topic/performance/vitals/launch-time

TuanPM
  • 685
  • 8
  • 29
  • I understand the difference between hot and cold start. That's not my problem, my problem is that the splash screen doesn't display at all. – Prescott Chartier Mar 04 '20 at 03:50