Bug 31027 - Crash when using "android:windowNoTitle"
Summary: Crash when using "android:windowNoTitle"
Alias: None
Product: Forms
Classification: Xamarin
Component: Android ()
Version: 1.4.4
Hardware: Macintosh Mac OS
: Normal normal
Target Milestone: ---
Assignee: Bugzilla
Depends on:
Reported: 2015-06-11 12:43 UTC by S. Chapman
Modified: 2016-04-10 00:16 UTC (History)
6 users (show)

Tags: ac
Is this bug a regression?: ---
Last known good build:

Sample Project (184.59 KB, application/zip)
2015-06-17 11:29 UTC, Ram Chandra

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Description S. Chapman 2015-06-11 12:43:23 UTC
When using a custom theme and specifying the "android:windowNoTheme" attribute, Xamarin Android will crash on launch.

Xamarin 5.9.3.

100% reproducible. I'm currently using a Xamarin.Forms project with Android. These are the following changes necessary:

In AndroidManifest.xml:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="1" android:versionName="1.0" package="com.unique.url">
	<uses-sdk android:minSdkVersion="16" />
	<application android:label="MyAppName" android:theme="@style/AppTheme"></application>

In Resources/values/styles.xml:

<?xml version="1.0" encoding="UTF-8" ?>
<resources xmlns:android="http://schemas.android.com/apk/res/android">
    <style name="AppTheme" parent="android:Theme.Material.Light">
        <item name="android:windowNoTitle">true</item>

Stack Trace:

Java.Lang.RuntimeException: java.lang.reflect.InvocationTargetException
  at --- End of managed exception stack trace ---
  at java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
  at at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
  at Caused by: java.lang.reflect.InvocationTargetException
  at at java.lang.reflect.Method.invoke(Native Method)
  at at java.lang.reflect.Method.invoke(Method.java:372)
  at at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
  at ... 1 more
  at Caused by: md52ce486a14f4bcd95899665e9d932190b.JavaProxyThrowable: System.NullReferenceException: Object reference not set to an instance of an object
  at at Xamarin.Forms.Platform.Android.Platform.UpdateActionBarHomeAsUp (Android.App.ActionBar) <IL 0x0001f, 0x000ad>
  at at Xamarin.Forms.Platform.Android.Platform.HideActionBar () <IL 0x0000d, 0x0005f>
  at at Xamarin.Forms.Platform.Android.Platform.UpdateActionBar () <IL 0x000a8, 0x0033f>
  at at Xamarin.Forms.Platform.Android.Platform.SetPage (Xamarin.Forms.Page) <IL 0x000c0, 0x003e3>
  at at Xamarin.Forms.Platform.Android.FormsApplicationActivity.InternalSetPage (Xamarin.Forms.Page) <IL 0x000be, 0x00413>
  at at Xamarin.Forms.Platform.Android.FormsApplicationActivity.SetMainPage () <IL 0x0000c, 0x00047>
  at at Xamarin.Forms.Platform.Android.FormsApplicationActivity.LoadApplication (Xamarin.Forms.Application) <IL 0x0002e, 0x00153>
  at Survey.Droid.MainActivity.OnCreate (Android.OS.Bundle) [0x0001f] in /Users/schapman/workspace/mobile-app/Droid/MainActivity.cs:23
  at Android.App.Activity.n_OnCreate_Landroid_os_Bundle_ (intptr,intptr,intptr) [0x00011] in /Users/builder/data/lanes/monodroid-mavericks-monodroid-5.1-series/d419c934/source/monodroid/src/Mono.Android/platforms/android-21/src/generated/Android.App.Activity.cs:2707
  at at (wrapper dynamic-method) object.87e07b4e-bb18-41b2-ac9c-c0b03c5c12d0 (intptr,intptr,intptr) <IL 0x00017, 0x00027>
  at at md511c276a106c3db27d5716a17eb9d595e.MainActivity.n_onCreate(Native Method)
  at at md511c276a106c3db27d5716a17eb9d595e.MainActivity.onCreate(MainActivity.java:29)
  at at android.app.Activity.performCreate(Activity.java:5990)
  at at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
  at at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278)
  at at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
  at at android.app.ActivityThread.access$800(ActivityThread.java:151)
  at at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
  at at android.os.Handler.dispatchMessage(Handler.java:102)
  at at android.os.Looper.loop(Looper.java:135)
  at at android.app.ActivityThread.main(ActivityThread.java:5254)
  at ... 4 more
Comment 1 Ram Chandra 2015-06-17 11:29:58 UTC
Created attachment 11646 [details]
Sample Project

I have checked this issue and I am also getting the same behavior.

Steps to reproduce:
1. Follow the steps provided in bug description or Run the attached project

Screencast: http://www.screencast.com/t/vHtKIT1V5

Exception Detail: https://gist.github.com/RamChBachkheti/c524e38ae929fdfc03b2
Application output: https://gist.github.com/RamChBachkheti/027c53fea90192f8a943
IDE logs: https://gist.github.com/RamChBachkheti/3748a7dadaa614484c74

Additional Info: I have follow the same steps with android project( Not forms project) an I am not getting any error/exception. It is working fine with android project (non Xamarin.Forms).

Environment Info: 


=== Xamarin Studio ===

Version 5.9.4 (build 4)
Installation UUID: 6ea47b0d-1852-4aaf-808d-373ff0a5002b
	Mono 4.0.2 ((detached/c99aa0c)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 400020005

=== Apple Developer Tools ===

Xcode 6.3 (7569)
Build 6D570

=== Xamarin.iOS ===

Version: (Enterprise Edition)
Hash: 4321ce6
Branch: master
Build date: 2015-06-13 07:53:11-0400

=== Xamarin.Android ===

Version: (Enterprise Edition)
Android SDK: /Users/jatin66/Desktop/Backup/android-sdk-macosx
	Supported Android versions:
		2.3    (API level 10)
		4.0.3  (API level 15)
		4.1    (API level 16)
		4.2    (API level 17)
		4.3    (API level 18)
		4.4    (API level 19)
		4.4.87 (API level 20)
		5.0    (API level 21)
Java SDK: /usr
java version "1.7.0_65"
Java(TM) SE Runtime Environment (build 1.7.0_65-b17)
Java HotSpot(TM) 64-Bit Server VM (build 24.65-b04, mixed mode)

=== Xamarin Android Player ===

Version: Unknown version
Location: /Applications/Xamarin Android Player.app

=== Xamarin.Mac ===

Version: (Enterprise Edition)

=== Build Information ===

Release ID: 509040004
Git revision: 0c8e73f6b66e066a642724a8241a0998b6329180
Build date: 2015-06-08 16:52:22-04
Xamarin addins: 7e93e9c3503f28770f23ce1b7eafd829919f18e8

=== Operating System ===

Mac OS X 10.10.3
Darwin Dalvik.local 14.3.0 Darwin Kernel Version 14.3.0
    Mon Mar 23 11:59:05 PDT 2015
    root:xnu-2782.20.48~5/RELEASE_X86_64 x86_64
Comment 2 Jonathan Pryor 2015-06-17 12:41:31 UTC
The crash is due to a NullReferenceException:

> [AndroidRuntime] Caused by: md52ce486a14f4bcd95899665e9d932190b.JavaProxyThrowable: System.NullReferenceException: Object reference not set to an instance of an object
> [AndroidRuntime] at Xamarin.Forms.Platform.Android.Platform.UpdateActionBarHomeAsUp (Android.App.ActionBar) <IL 0x0001f, 0x000ad>

This is presumably because Activity.getActionBar() is returning null:


What I don't understand is *why* this would happen.

(One Google search later...)


> You also need your Activity's window to have the title visible.

TL;DR: It seems that a window title is REQUIRED in order for Activity.getActionBar() to return non-null, and the app explicitly removes the window title by using android:windowNoTitle.

Which means the real "bug" is that Xamarin.Forms doesn't support title-less Windows.

Either Xamarin.Forms should support the lack of an ActionBar, or it should explicitly check for this and report an exception if the ActionBar is required.
Comment 3 Willem Mali 2016-03-09 11:04:43 UTC
I also encounter this bug whenever I use Theme.Holo.Light.NoActionBar or when I set windowNoTitle, except that I get a NullReferenceException in UpdateActionBarBackgroundColor.

Any news on this bug? Will this be fixed or are we stuck with splashscreens that always contain an action bar?
Comment 4 Willem Mali 2016-03-09 11:09:05 UTC
I'm developing on Windows 8.1, using the latest Xamarin (stable branch) and I get this on Android 5.1.1 and 4.3, I haven't tested other Android versions.
Comment 5 migs 2016-04-07 11:35:11 UTC
This bug is almost a year old... Any updates?
Comment 6 Jason Smith [MSFT] 2016-04-10 00:16:22 UTC
At this time there are no plans to implement any changes to support titlebar less themes.

Warm regards,
Xamarin Forms Team