Does anybody have splashscreen appearing in app deployed on Amazon Fire?

JohnHardmanJohnHardman GBUniversity mod

I just added an Amazon Fire tablet to my collection of physical devices for testing. Everything seems to work fine, other than the splash screen does not appear (if it does, it vanishes before the human eye can see it). Has anybody else tested an app with a splashscreen on Amazon Fire? If so, how did you get it to work? The code I am using for my launcher activity is below, based on a sample somebody else published a while back.

Many thanks,

John H.

using System.Threading;
using System.Threading.Tasks;

using Android;
using Android.App;
using Android.Content;
using Android.Content.PM;
using Android.Views;
using Android.OS;

using Xamarin.Forms.Platform.Android;

namespace MarvinPrototype.Droid
{
    [Activity(
    ConfigurationChanges = ConfigChanges.Orientation | ConfigChanges.ScreenSize,
    Icon = "@drawable/icon",
    Label = "MarvinPrototype",
    LaunchMode = LaunchMode.SingleInstance,
    MainLauncher = true,
    NoHistory = true,
    ScreenOrientation = ScreenOrientation.FullSensor,
    Theme = "@style/Theme.Splash",
    WindowSoftInputMode = SoftInput.AdjustPan)]
    public class LaunchActivity : Activity
    {
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            System.Threading.Thread.Sleep(3000);
            StartActivity(typeof(MainActivity));
        }
    }
}

Best Answer

  • JohnHardmanJohnHardman GB mod
    Accepted Answer

    After 3 years (ok, I did other things in between), finally identified what was required to get a splash screen to appear on Amazon Fire.

    At some point, I changed to the "Better Approach" described at https://xamarinhelp.com/creating-splash-screen-xamarin-forms/ . Whilst that worked on other Android devices, it didn't display a splash screen on Amazon Fire. The change required is simple - it just needs the UI thread to be freed up momentarily so that the splash screen can be displayed (or that's my assumption based on observation).

    So, I add a little helper to identify Amazon devices (I'm assuming that all Amazon devices run Fire for the moment):

            public static bool IsAmazonDevice 
                => string.Equals(Android.OS.Build.Manufacturer, "Amazon", StringComparison.InvariantCultureIgnoreCase);
    

    and then free up the UI thread using a call to Task.Delay just before calling LoadApplication:

                    if (IsAmazonDevice)
                        await Task.Delay(100);
                    LoadApplication(new App());
    

    Thanks to @batmaci for a nudge that got me looking at this again :-)

Answers

  • JohnHardmanJohnHardman GBUniversity mod

    Whilst my splash screen code has changed since the original question (over a year and a half ago), I still don't see a splash screen on my Amazon Fire tablet. Has anybody managed to get a splash screen to appear on Amazon Fire? If so, what did you have to do?

  • batmacibatmaci DEMember ✭✭✭✭✭

    Are you testing on a real device? is there an emulator to test Amazon Fire tablet or any amazon device?

  • JohnHardmanJohnHardman GBUniversity mod

    @batmaci - I use a real device. I haven't investigated whether there is an available emulator.

  • JGoldbergerJGoldberger USMember, Forum Administrator, Xamarin Team, University Xamurai
    edited August 2018

    @JohnHardman

    Have you verified that your Thread.Sleep is being respected? Try placing a breakpoint on System.Threading.Thread.Sleep(3000); and on the next line as well. Then debug your app and when it breaks on the Thread.Sleep line, hit Continue and see how long it takes to break on the next line. Adjust the value passed in to Thread.Sleep and see if that time changes. I have to suspect that that Thread.Sleep is not being respected for some reason, maybe some change Amazon made to their version of Android?

    Also moving this thread to Xamarin.Android category

  • JohnHardmanJohnHardman GBUniversity mod

    Thanks @JGoldberger . Unfortunately, it's not that - both Thread.Sleep and Task.Delay are respected.

  • JGoldbergerJGoldberger USMember, Forum Administrator, Xamarin Team, University Xamurai

    @JohnHardman

    Unfortunately I do not have an Amazon Fire to test on. This is only occurring on that device? Does the MainActivity show up when it should, i.e. after a 3 second delay?

    All that said, I have to think, if this issue only occurs on Amazon Fire, that this is a difference between Fire OS and standard Android. Amazon makes some pretty heavy changes to Android for their Fire OS to the point that some refuse to even call it Android anymore. See: https://www.gadgetsalvation.com/blog/2016/01/05/the-difference-between-amazons-fire-os-and-googles-android/

    Not sure if this is relevant, but on looking up developing for Fire OS, I came across this document about building Fire OS apps: https://developer.amazon.com/docs/fire-app-builder/customize-look-and-feel.html

    In the section about Splash Screens there is this tidbit:

    Note: The duration of the splash screen depends on the time required to load content from your app's media feed.

    Which suggests to me that as soon as the main activity is ready, the Splash Screen will disappear.... of course this still makes no sense as to how and why Fire OS is ignoring your main launcher activity. However you said the Thread.Sleep s respected... but then how does the main activity get launched before thread.sleep finishes?

    All this is very odd, but as a test try putting a delay in the OnCreate method of your main activity and see if that forces the splash screen to stay on screen longer.

    If that does not help, I do not know what else to tell you except perhaps bring it up with the Amazon Developer community.

  • JohnHardmanJohnHardman GBUniversity mod

    @JGoldberger said:
    This is only occurring on that device?

    Of the multiple Android (& derivative) test devices that I have, yes - it's just the Amazon Fire device that isn't showing the splash screen.

    @JGoldberger said:
    Does the MainActivity show up when it should, i.e. after a 3 second delay?

    It's hard to tell, due to the start-up time, but it's never less than 3 seconds.

    @JGoldberger said:
    All that said, I have to think, if this issue only occurs on Amazon Fire, that this is a difference between Fire OS and standard Android

    My thoughts too. I've seen a couple of other people in the forums recently mention that they publish to Amazon Fire, so was hoping somebody would know what has to be done differently. I might direct-message them to see if they have any insights on this.

    @JGoldberger said:
    However you said the Thread.Sleep s respected... but then how does the main activity get launched before thread.sleep finishes?

    Not sure I understand the question. Note, however, that the code being used has changed since that shown in the first post above, to use what @AdamP published some time back as a better approach. However, in my experience, neither approach (the above, or @AdamP's better one) shows a splash screen on Amazon Fire, whilst both do on all of my other Android(y) test devices.

    @JGoldberger said:
    All this is very odd, but as a test try putting a delay in the OnCreate method of your main activity and see if that forces the splash screen to stay on screen longer.

    Will give that a go shortly. Investigating the Xamarin Component - related message from VS at the moment.

  • JohnHardmanJohnHardman GBUniversity mod
    Accepted Answer

    After 3 years (ok, I did other things in between), finally identified what was required to get a splash screen to appear on Amazon Fire.

    At some point, I changed to the "Better Approach" described at https://xamarinhelp.com/creating-splash-screen-xamarin-forms/ . Whilst that worked on other Android devices, it didn't display a splash screen on Amazon Fire. The change required is simple - it just needs the UI thread to be freed up momentarily so that the splash screen can be displayed (or that's my assumption based on observation).

    So, I add a little helper to identify Amazon devices (I'm assuming that all Amazon devices run Fire for the moment):

            public static bool IsAmazonDevice 
                => string.Equals(Android.OS.Build.Manufacturer, "Amazon", StringComparison.InvariantCultureIgnoreCase);
    

    and then free up the UI thread using a call to Task.Delay just before calling LoadApplication:

                    if (IsAmazonDevice)
                        await Task.Delay(100);
                    LoadApplication(new App());
    

    Thanks to @batmaci for a nudge that got me looking at this again :-)

  • batmacibatmaci DEMember ✭✭✭✭✭
    I created totaly separate Android project for Amazon and a shared Android class library. I copied everything shared between Amazon and Google projects into that shared, anything else remains specific. Thus i could even spare some nugets which only work on google like firebase, applink, google iap. Amazon has own iap using Amazon nuget. Also Manifest settings can be separated with this architecture.
  • JohnHardmanJohnHardman GBUniversity mod

    @batmaci - Excellent idea. If I find that I need to handle more differences for Amazon Fire, I'll do the same.

Sign In or Register to comment.