Rinze Douma
Rinze Douma

Reputation: 21

Why is my Xamarin Forms app on top of everything else in Android 4.4 - API 19 (Samsung Galaxy S3)?

I've Got this weird situation with my Xamarin Forms (version 2.3.2.127) app on Android 4.4 API 19, running on a Samsung Galaxy S3. When running the app (at least in debug mode) it's on top of the whole Android interface - including the soft keyboard, status bar slide out and alerts. Basically just everything. As you can imagine this is very bad, because I cannot see the soft keyboard when focussing an entry field. When I tab the spot where the soft keyboard would normaly appear, it does input the touched letters. This indicates that the keyboard is accually there, but just visually behind the app interface.

When I test the app on Android API 21 (Galaxy S7 Edge) everything works as expected. Also on WP 8.1 and iOS (iPhone 4s and iPhone 6) it works just fine.

Splashscreen.cs

First the app opens a splash screen, at this point it doesn't overlay the Android OS jet:

[Activity(Label = "Mett Login", MainLauncher = true, NoHistory = true, Theme = "@style/Theme.Splash", Icon = "@drawable/icon", ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation, ScreenOrientation = ScreenOrientation.Portrait)]
public class SplashScreen : Activity
{
    protected override void OnCreate(Bundle bundle)
    {
        base.OnCreate(bundle);

        var intent = new Intent(this, typeof(MainActivity));
        StartActivity(intent);
    }
}

MainActivity.cs

After that it runs the main activity class. This is where the weird things start to happen:

[Activity(Label = "Mett Login", Theme = "@android:style/Theme.DeviceDefault", ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]
public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsApplicationActivity
{
    protected static ActionBar mActionBar;
    protected static Window mWindow;

    protected override void OnCreate (Bundle bundle)
    {
        Window.AddFlags(WindowManagerFlags.DrawsSystemBarBackgrounds);

        base.OnCreate (bundle);

        global::Xamarin.Forms.Forms.Init (this, bundle);
        LoadApplication (new MettAuthenticator.App ());

        ActionBar.SetIcon(Android.Resource.Color.Transparent);

        mActionBar = ActionBar;
        mWindow = Window;

        if(IsPlayServicesAvailable())
        {
            Intent intent = new Intent(this, typeof(RegistrationIntentService));
            StartService(intent);
        }
    }

    [Some extra code...]
}

The only thing about apps being always on top I could find had to do with people wanted to use (a part of) their app as a system alert, using the SYSTEM_ALERT_WINDOW permission. I've tried to use some of the things I've found recoring to this topic to undo the always on top functionallity, but unfortunately nothing helped.

Please let me know if you need extra information to give me the correct anwser.

Upvotes: 1

Views: 222

Answers (1)

Rinze Douma
Rinze Douma

Reputation: 21

I've found the solution myself!

The problem causing this is the following line:

Window.AddFlags(WindowManagerFlags.DrawsSystemBarBackgrounds);

This flag is not available before SDK 21. Somehow it causes the app to overlay the entire Android interface. I've fixed it by adding a single line:

if ((int)Build.VERSION.SdkInt >= 21)
    Window.AddFlags(WindowManagerFlags.DrawsSystemBarBackgrounds);

Upvotes: 1

Related Questions