Android Oreo(8.0) on back displays splash screen

SuchithSuchith INMember ✭✭

I have observed this strange behavior with android 8.0 devices.

On app lunch shows splash screen as expected and moves to next activity(MainActivity). If i press back button in MainActivity it shows splash screen again for a moment and moves back to MainActivity by itself.

This happens only in Android 8.0 devices checked in Samsung S7 and Nexus 5X. Where as it worked without any issue in Android 5.0(Samsung J7).

Here i have added NoHistory = true in my splash activity as well in splash theme. Splash screen code similar to the one explained here: xamarin android splash

Things i tried:

Adding oreo property(V26 style) android:windowSplashscreenContent instead of android:windowBackground in theme. example link
Adding finish() in splash screen after navigation it works but shows some crash effect moreover i want to know the reason for the above behavior.
Appreciated for any hints/root-cause for this issue. Thanks

Best Answer

Answers

  • yelinzhyelinzh Member, Xamarin Team Xamurai

    Adding finish() in splash screen after navigation it works but shows some crash effect.

    With NoHistory = true attribute set on SplashActivity, there's no need to call Finish, activity is automatically finished when another one is opened.

    Why the app crashed you can refer to the link.

  • SuchithSuchith INMember ✭✭
    edited May 15

    @yelinzh thanks for the response

    With NoHistory = true attribute set on SplashActivity, there's no need to call Finish, activity is automatically finished when another one is opened

    Yes this is the fact, just to override this behaviour(on back button press from mainactivity showing splash screen for a moment and coming back to mainactivity by itself) added that workaround.

    Here crash is not my concern, only question is why splash is showing up even though i added NoHistory = true attribute?

    Here is the code,

    `[Activity(Theme = "@style/MyTheme.Splash", MainLauncher = true, NoHistory = true)]
    public class SplashActivity : AppCompatActivity
    {
    public override void OnCreate(Bundle savedInstanceState, PersistableBundle persistentState)
    {
    base.OnCreate(savedInstanceState, persistentState);
    }

        // Launches the startup task
        protected override void OnResume()
        {
            base.OnResume();
            Task startupWork = new Task(SimulateStartup);
            startupWork.Start();
        }
    
        // Simulates background work that happens behind the splash screen
        private async void SimulateStartup()
        { 
            await Task.Delay(1000); // Simulate a bit of startup work. 
            StartActivity(new Intent(Application.Context, typeof(MainActivity)));
            //Finish();
        }
        public override void OnBackPressed()
        {
            base.OnBackPressed();
        }
    }`
    

    --Splash theme

    <style name="My.Splash" parent ="Theme.AppCompat.Light.NoActionBar"> <item name="android:windowBackground">@mipmap/ic_splash</item> <!--<item name="android:windowBackground">@drawable/splash_screen</item>--> <item name="android:windowNoTitle">true</item> <item name="android:noHistory">true</item> <item name="android:windowFullscreen">true</item> </style>
    --ic_splash -is the png image used for splash, even tried with bitmap xml, same result

  • yelinzhyelinzh Member, Xamarin Team Xamurai

    I've reproduced your code on Android 8.0 Nexus 5X and it works well. Would you mind sharing a basic? It'll help to reproduce the issue and get a solution.

  • SuchithSuchith INMember ✭✭

    @yelinzh Sure, i have shared here sample app source code depicting the same behaviour.

    My device screen recording added here . Please let me know if you need any other details.

  • yelinzhyelinzh Member, Xamarin Team Xamurai

    @Suchith
    I've deployed you demo on Android 8.0 Nexus 5X .
    Try to change the code in OnResume and SimulateStartup method as follows:

    protected override void OnResume()
    {
        base.OnResume();
    
        //var intent = new Intent(Application.Context, typeof(MainActivity));
        StartActivity(new Intent(Application.Context, typeof(MainActivity)));
        Finish();
    }
    private async void SimulateStartup()
    {
        await Task.Delay(500); // Simulate a bit of startup work. 
        var intent = new Intent(Application.Context, typeof(MainActivity));
        intent.SetFlags(ActivityFlags.ClearTop);
        StartActivity(intent);
        //Finish();
    }
    

  • SuchithSuchith INMember ✭✭

    @yelinzh
    I think you added here Finish() after StartActivity(). Just i wanted to know why we need to use Finish() when we set noHistory=true.

    I've reproduced your code on Android 8.0 Nexus 5X and it works well

    Can you share this code base (App6) just to know where i missed.
    Thanks

  • yelinzhyelinzh Member, Xamarin Team Xamurai

    @Suchith
    Sure, my demo is here.

  • SuchithSuchith INMember ✭✭

    @yelinzh In your last post image, if we observe closely when splash screen(green screen) navigates to mainactivity(white screen) kind of crash effect we could observe which looks odd. mostly this is happening because of Finish().

  • yelinzhyelinzh Member, Xamarin Team Xamurai
    edited May 15 Accepted Answer

    @Suchith
    Delete or comment the item I marked in the picture.

    About windowIsTranslucent : https://tech.pic-collage.com/something-about-android-windowistranslucent-641cc02ff66f

  • yelinzhyelinzh Member, Xamarin Team Xamurai

    @Suchith
    I delete Finish() method and add 'Nohistory=true' in SplashActivity. Then delete the item as above shows. It works well.
    SplashActivity.cs

    namespace SampleSplash.Droid
    {
        [Activity(Theme = "@style/InspectTheme.Splash", Label = "SampleSplash", MainLauncher = true, Icon = "@mipmap/icon", NoHistory = true)]
        public class SplashActivity : AppCompatActivity
        {
            public override void OnCreate(Bundle savedInstanceState, PersistableBundle persistentState)
            {
                base.OnCreate(savedInstanceState, persistentState);
    
            }
            // Launches the startup task
            protected override void OnResume()
            {
                base.OnResume();
                StartActivity(new Intent(Application.Context, typeof(MainActivity)));
            }
            private async void SimulateStartup()
            {
                await Task.Delay(500); // Simulate a bit of startup work. 
                var intent = new Intent(Application.Context, typeof(MainActivity));
                intent.SetFlags(ActivityFlags.ClearTop);
                StartActivity(intent);
            }
            public override void OnBackPressed()
            {
                base.OnBackPressed();
            }
        }
    }
    

  • SuchithSuchith INMember ✭✭

    @yelinzh Great catch! and thanks for fully engaging with this issue and providing solution.

    There is a conflict with android 8.0 and android:windowIsTranslucent property. which is causing the sliding activity over another activity.
    There is already reported similar issues like, exception with using portrait mode and android:windowIsTranslucent together in android 8.0(Oreo) here.

Sign In or Register to comment.