Actually, it's not a bug, on Xamarin Forms you can't have more than one classe inheriting from FormsApplicationActivity, I change the splash screen base classe to Activity and now, everything is working fine! Thanks to Xamarin support
@nbevans I tried your solution and it is definitely much cleaner than the separate SplashActivity. However, the latest versions of Xamarin.Forms use a LoadApplication( new App() ); call in the MainActivity template. This call crashes with a NullReference when using your solution. If I remove the theme, it works fine. Any ideas? Thanks in advance!
@TikiMotel I tested our app last week on 1.3.x and the splash was still working fine? As it happens we had an issue elsewhere and had to rollback for the time being.
I only made the minimalist of changes concerning LoadApplication etc but functionally nothing much had changed from the original example code I pasted on this thread.
@nbevans thanks for the response. I've found a couple other posts with the same issue I'm facing, with no resolution. I'm not sure what I'm doing differently. The new LoadApplication() call and inheriting from FormsApplicationActivity are the only differences I can find. Out of curiosity, what's your min Android version?
Unfortunately, it 100% comes and goes with addition of the Theme to the MainActivity. As soon as I add Theme= @style/Theme.Foo, then LoadApplication() crashes. Remove the Theme, works fine. It also works fine if I have the theme on a separate SplashActivity but not on the MainActivity. Bizarre.
DanielL, I am new to Xamarin Forms, could you update a sample code, how to do splash screen for iOS and Andorid in PCL coding, only put the images in respective resources.
hello friends , me to have problem in splash screen according to me my app have a theme when i add the theme for splash, it makes error while the theme removed it works but no images displaying on it , now splash screen is displaying but no image in the activity (shall we add one theme only for the splash and other for the remaining app )
I'm not (currently) an Android person, so forgive me if this is a newbie question.
When a splash screen is displayed, if the user changes the orientation, what needs to be done to prevent the splash screen's aspect ratio being changed to stretch the same image to fit the new width/height? Are two images supplied, or is there some way of saying to maintain the aspect ratio and pad the rest with a particular color (or similar)?
@JohnHardman:
I have tried to implement an Android splash screen that works as expected for all situations... and gave up after days... (there are simply very (too) many cryptic android options).
I have found a solution now with only one Image that is scaled mostly correct (in some case the aspect ratio is not kept correct 100% but maybe 80%).
The quality is not optimal on any device, but for me it's O.K. (I don't want to spend further days to find out, how to implement it for any case, any device and any device-resolution correct and add a lot of further images to the project).
But.. I'm also not an "Android person"
Let's see, if you receive a good (better) answer here...
If not (and the splash screen don't have to be perfect for you ), feel free to ask me again...
I followed what's been said in this post. My app compiles and run fine (XF 2.0) but no splascreen just a black screen.
The Splascreen.xml file is taken into account as if I change the bitmap src to a non existing file the project doesn't compile.
Here is my code.
Proposed solution works great. Unfortunately my app takes a while to initialize (about 2-3 secs) at the MainActivity.OnCreate method. So in the scenario above I can see nice splash screen, then it disappears and I see my ugly while background of MainActivity and navigation bar for 2-3 seconds (which shouldn't be there at all). I applied same style for main activity to change background and hide actionbar but in this case Xamarin.Forms throws an exception:
System.NullReferenceException: Object reference not set to an instance of an object
at Xamarin.Forms.Platform.Android.Platform.UpdateActionBarBackgroundColor () [0x00010] in <filename unknown>:0
at Xamarin.Forms.Platform.Android.Platform.set_CurrentNavigationPage (Xamarin.Forms.NavigationPage value) [0x000f1] in <filename unknown>:0
at Xamarin.Forms.Platform.Android.Platform.UpdateActionBar () [0x00063] in <filename unknown>:0
at Xamarin.Forms.Platform.Android.Platform.SetPage (Xamarin.Forms.Page newRoot) [0x000bd] in <filename unknown>:0
at Xamarin.Forms.Platform.Android.FormsApplicationActivity.InternalSetPage (Xamarin.Forms.Page page) [0x000b7] in <filename unknown>:0
at Xamarin.Forms.Platform.Android.FormsApplicationActivity.SetMainPage () [0x0000c] in <filename unknown>:0
at Xamarin.Forms.Platform.Android.FormsApplicationActivity.LoadApplication (Xamarin.Forms.Application application) [0x0002d] in <filename unknown>:0
at Droid.MainActivity.OnCreate (Android.OS.Bundle bundle) [0x0003a] in
Can I initialize Xamarin.Forms app at SplashScreen activity and then when it's ready navigate to MainActivity?
@nbevans Great solution. Two questions for you (or anyone else following this post):
What does the code base.Window.RequestFeature(WindowFeatures.ActionBar); do? I ran my app with and without it and I can't see the difference. I did find this android reference, that says that it, "Enable[s] extended screen features", but I am not sure what that means.
I found a post on Stack Overflow that referenced this site that says splash screens can lead to memory leaks because of the strong association with the parent, preventing garbage collection. Have you seen any evidence of that with this approach?
This does work fine to show the splash screen, but is there a way to stop it from registering input?
When the splash screen is shown and you touch the screen, as soon as the main activity shows this input is executed. For example if I tap the splash screen at the position where my first activity has a button, this button is pressed as soon as the activity shows.
IMO the splash screen shouldn't capture any touch input at all.
Has anybody solved the problem of the splash screen aspect ratio not being maintained if the user changes the orientation on Android? At the moment, my splash screen is getting stretched horizontally if the user changes the Android device to have landscape orientation.
I found a better solution (at least it claims to be better) at https://xamarinhelp.com/creating-splash-screen-xamarin-forms/ . It uses a theme switch technique which I found indeed better in old android phones because it avoids the activity switch flash.
Posts
Actually, it's not a bug, on Xamarin Forms you can't have more than one classe inheriting from FormsApplicationActivity, I change the splash screen base classe to Activity and now, everything is working fine! Thanks to Xamarin support
Thanks @Alexandrem !
Mine was crashing because I had the Splash activity inheriting from "AndroidActivity" instead of just "Activity"
@nbevans I tried your solution and it is definitely much cleaner than the separate SplashActivity. However, the latest versions of Xamarin.Forms use a LoadApplication( new App() ); call in the MainActivity template. This call crashes with a NullReference when using your solution. If I remove the theme, it works fine. Any ideas? Thanks in advance!
@TikiMotel I tested our app last week on 1.3.x and the splash was still working fine? As it happens we had an issue elsewhere and had to rollback for the time being.
I only made the minimalist of changes concerning LoadApplication etc but functionally nothing much had changed from the original example code I pasted on this thread.
@nbevans thanks for the response. I've found a couple other posts with the same issue I'm facing, with no resolution. I'm not sure what I'm doing differently. The new LoadApplication() call and inheriting from FormsApplicationActivity are the only differences I can find. Out of curiosity, what's your min Android version?
API 17... target 21.
I think the issue you have is something else, unrelated to the Zygote-based splash screen.
Unfortunately, it 100% comes and goes with addition of the Theme to the MainActivity. As soon as I add Theme= @style/Theme.Foo, then LoadApplication() crashes. Remove the Theme, works fine. It also works fine if I have the theme on a separate SplashActivity but not on the MainActivity. Bizarre.
Does anybody have this problem: Open the app, press back button (the app closes), Open the app and navigate to any place: The app crashes!
DanielL, I am new to Xamarin Forms, could you update a sample code, how to do splash screen for iOS and Andorid in PCL coding, only put the images in respective resources.
Alternatively you can email also : [email protected]
Thanks
hello friends , me to have problem in splash screen according to me my app have a theme when i add the theme for splash, it makes error while the theme removed it works but no images displaying on it , now splash screen is displaying but no image in the activity (shall we add one theme only for the splash and other for the remaining app )
update for my comment
my error solved it works fine now
@Mike.9461 There's no difference when using PCL project
I'm not (currently) an Android person, so forgive me if this is a newbie question.
When a splash screen is displayed, if the user changes the orientation, what needs to be done to prevent the splash screen's aspect ratio being changed to stretch the same image to fit the new width/height? Are two images supplied, or is there some way of saying to maintain the aspect ratio and pad the rest with a particular color (or similar)?
Thanks,
John H.
@JohnHardman:
), feel free to ask me again...
I have tried to implement an Android splash screen that works as expected for all situations... and gave up after days... (there are simply very (too) many cryptic android options).
I have found a solution now with only one Image that is scaled mostly correct (in some case the aspect ratio is not kept correct 100% but maybe 80%).
The quality is not optimal on any device, but for me it's O.K. (I don't want to spend further days to find out, how to implement it for any case, any device and any device-resolution correct and add a lot of further images to the project).
But.. I'm also not an "Android person"
Let's see, if you receive a good (better) answer here...
If not (and the splash screen don't have to be perfect for you
Hi,
I followed what's been said in this post. My app compiles and run fine (XF 2.0) but no splascreen just a black screen.
The Splascreen.xml file is taken into account as if I change the bitmap src to a non existing file the project doesn't compile.
Here is my code.
MainAtivty.cs
Styles.xml
SplashScreen.xml
Hi guys!
Proposed solution works great. Unfortunately my app takes a while to initialize (about 2-3 secs) at the MainActivity.OnCreate method. So in the scenario above I can see nice splash screen, then it disappears and I see my ugly while background of MainActivity and navigation bar for 2-3 seconds (which shouldn't be there at all). I applied same style for main activity to change background and hide actionbar but in this case Xamarin.Forms throws an exception:
Can I initialize Xamarin.Forms app at SplashScreen activity and then when it's ready navigate to MainActivity?
@nbevans Thanks a lot! It work at the first try. Is there a way how to make the splash screen full screen?
@nbevans Great solution. Two questions for you (or anyone else following this post):
What does the code
base.Window.RequestFeature(WindowFeatures.ActionBar);
do? I ran my app with and without it and I can't see the difference. I did find this android reference, that says that it, "Enable[s] extended screen features", but I am not sure what that means.I found a post on Stack Overflow that referenced this site that says splash screens can lead to memory leaks because of the strong association with the parent, preventing garbage collection. Have you seen any evidence of that with this approach?
This does work fine to show the splash screen, but is there a way to stop it from registering input?
When the splash screen is shown and you touch the screen, as soon as the main activity shows this input is executed. For example if I tap the splash screen at the position where my first activity has a button, this button is pressed as soon as the activity shows.
IMO the splash screen shouldn't capture any touch input at all.
Has anybody solved the problem of the splash screen aspect ratio not being maintained if the user changes the orientation on Android? At the moment, my splash screen is getting stretched horizontally if the user changes the Android device to have landscape orientation.
@JohnHardman have you tried using a 9-patch image?
I'd be curious as the same issue existed with 9-patch images in Icenium (Appbuilder).
This is the perfect solution thank you so much Daniel Luberda
https://developer.xamarin.com/guides/android/user_interface/creating_a_splash_screen/
How do I use base.SetTheme(); to set a theme I have defined in my styles.xml, so just MainTheme ?
I did my splash screen based on your examples and it worked here are my files.
I am using "Blank App (Xamarin Forms Portable"
MainActivity.cs
SplashScreen.cs
styles.xml
SplashScreen.xml
hmm im getting 2 launch icons like there is 2 seperate projects installed
Set MainLauncher = false on your MainActivity
I found a better solution (at least it claims to be better) at https://xamarinhelp.com/creating-splash-screen-xamarin-forms/ . It uses a theme switch technique which I found indeed better in old android phones because it avoids the activity switch flash.
@CTPAX Use jdk 8 instead of jdk 9. It will solve NullReferenceException
Hi Xamarin,
I have stucked on a issue while adding Splash screen. I have implement the splash screen with help of this link.
After that the app crashed. and show the given error popup.
Please help me
Thank you
I couldn't get these examples to work, but I was able to put something together..
MainActivity.cs
SplashScreen.cs
Resources\Values\Styles.xml
Resourse\drawable\background_splash.axml
https://xamarinhelp.com/creating-splash-screen-xamarin-forms/
You do not need to create an SplashActivity, just add this line of xml to the current used style at MainActivity.
In drawable and splash background (splash_screen.xml)
The icon is in drawable ic_lancher.png