Suchith
Suchith

Reputation: 1527

Android Oreo(8.0) on back displays splash screen

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:

Appreciated for any hints/root-cause for this issue. Thanks

Edit: Code splash activity:

[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()
    {

    }
}

Theme:

  <style name="InspectTheme.Splash" parent ="Theme.AppCompat.Light.NoActionBar"> 
<!--<item name="android:windowSplashscreenContent">@mipmap/ic_splash</item>-->
<item name="android:windowBackground">@mipmap/ic_splash</item>
<item name="android:windowNoTitle">true</item>
<item name="android:noHistory">true</item>
<item name="android:windowFullscreen">true</item>

Added device screen recording here

Sample code uploaded here

Upvotes: 2

Views: 636

Answers (1)

Leon Lu
Leon Lu

Reputation: 9234

I test your code in my device, this issue is related to

<item name="android:windowIsTranslucent">true</item> in InspectTheme of styles.xml.

If I delete this line, this GIF is running result.

enter image description here

There is styles.xml now

<?xml version="1.0" encoding="UTF-8" ?>
<resources>
<style name="InspectTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowNoTitle">true</item>
<item name="android:windowActionBar">false</item> 
<item name="android:windowContentOverlay">@null</item>

<item name="android:textAllCaps">false</item> 
 </style>


 <style name="InspectTheme.Splash" parent ="Theme.AppCompat.Light.NoActionBar"> 
<!--<item name="android:windowSplashscreenContent">@mipmap/ic_splash</item>-->
<item name="android:windowBackground">@mipmap/ic_splash</item>
<item name="android:windowNoTitle">true</item>
<item name="android:noHistory">true</item>
<item name="android:windowFullscreen">true</item>
    </style>
</resources> 

Upvotes: 1

Related Questions