Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SoftInput.AdjustResize causes keyboard to flash when showing or hiding

We are having an issue in Android after setting WindowSoftInputMode to Android.Views.SoftInput.AdjustResize. When the keyboard shows or hides, our splash screen flashes right above where the keyboard is animating. This is quite annoying and jarring.

Here is a clip of it, you can see the splash is peeking behind.

like image 246
James Esh Avatar asked Nov 06 '22 09:11

James Esh


1 Answers

From what I can see this might be the issue. If you set SplashScreen in Styles.xml something like this:

<style name="MainTheme.Splash" parent ="Theme.AppCompat.Light.NoActionBar">
    <item name="android:windowBackground">@drawable/splashscreen</item>
    <item name="android:windowNoTitle">true</item>
    <item name="android:windowFullscreen">true</item>
  </style>

And than just set the LoginActivity (login screen) as an MainLaucher the splashscreen is never disposed and it will live through your whole app. Imagine having bigger image on splash screen and drag it trough the whole app it will cause memory leaks after a while.


How to fix it. Create something like middleware activity which will be the same as the splash screen something like this

[Activity(Theme = "@style/MainTheme.Splash", MainLauncher = true, NoHistory = true, Icon = "@drawable/appicon")]
    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
        async void SimulateStartup()
        {
            await Task.Delay(500); // Simulate a bit of startup work. You can remove this 
            StartActivity(typeof(LoginActivity)); // Your Activity

        }
    }
}

Than just use a fresh LoginActivity

[Activity(Label = "LoginActivity")]
    public class LoginActivity : AppCompatActivity
    {
    }
like image 108
Stefanija Avatar answered Nov 15 '22 14:11

Stefanija