Reputation: 707
My Android app (created using Xamarin.Forms) takes around 10 seconds to start (both in Debug & Release mode) on a real device (Asus Zenfone 2). The splash screen is showing for 8 seconds. Here is my log attached where as "extrony" is my app name. Only assembly loading takes this much time. Any help?
EDIT 1: It actually takes 10 seconds (I mentioned 8 by mistake, but updated now)
EDIT 2: On an Emulator (I am using Android Emulator for Visual Studio) the app starts faster i.e. within 4.3seconds. However on my real device (Asus Zenfone2), the time it takes is 10seconds. Here is additional thing I see on the debug output while debugging on a real device (It doesn't appear if you debug on the emulator) and loading these assemblies ALONE takes ~6seconds.
Android application is debugging.
Loaded assembly: /storage/emulated/0/Android/data/com.abdullah.extrony/files/.__override__/extrony.Droid.dll
Loaded assembly: /storage/emulated/0/Android/data/com.abdullah.extrony/files/.__override__/Acr.Support.Android.dll [External]
Loaded assembly: /storage/emulated/0/Android/data/com.abdullah.extrony/files/.__override__/Acr.UserDialogs.dll [External]
Loaded assembly: /storage/emulated/0/Android/data/com.abdullah.extrony/files/.__override__/Acr.UserDialogs.Interface.dll [External]
Loaded assembly: /storage/emulated/0/Android/data/com.abdullah.extrony/files/.__override__/AndHUD.dll [External]
Loaded assembly: /storage/emulated/0/Android/data/com.abdullah.extrony/files/.__override__/CarouselView.FormsPlugin.Abstractions.dll [External]
Loaded assembly: /storage/emulated/0/Android/data/com.abdullah.extrony/files/.__override__/CarouselView.FormsPlugin.Android.dll [External]
Loaded assembly: /storage/emulated/0/Android/data/com.abdullah.extrony/files/.__override__/FFImageLoading.dll [External]
Loaded assembly: /storage/emulated/0/Android/data/com.abdullah.extrony/files/.__override__/FFImageLoading.Forms.dll [External]
Loaded assembly: /storage/emulated/0/Android/data/com.abdullah.extrony/files/.__override__/FFImageLoading.Forms.Droid.dll [External]
Loaded assembly: /storage/emulated/0/Android/data/com.abdullah.extrony/files/.__override__/FFImageLoading.Platform.dll [External]
Loaded assembly: /storage/emulated/0/Android/data/com.abdullah.extrony/files/.__override__/FormsViewGroup.dll [External]
Loaded assembly: /storage/emulated/0/Android/data/com.abdullah.extrony/files/.__override__/HtmlAgilityPack.dll [External]
Loaded assembly: /storage/emulated/0/Android/data/com.abdullah.extrony/files/.__override__/Microsoft.Azure.Mobile.Analytics.Android.Bindings.dll [External]
Loaded assembly: /storage/emulated/0/Android/data/com.abdullah.extrony/files/.__override__/Microsoft.Azure.Mobile.Analytics.dll [External]
Loaded assembly: /storage/emulated/0/Android/data/com.abdullah.extrony/files/.__override__/Microsoft.Azure.Mobile.Android.Bindings.dll [External]
Loaded assembly: /storage/emulated/0/Android/data/com.abdullah.extrony/files/.__override__/Microsoft.Azure.Mobile.Crashes.Android.Bindings.dll [External]
Loaded assembly: /storage/emulated/0/Android/data/com.abdullah.extrony/files/.__override__/Microsoft.Azure.Mobile.Crashes.dll [External]
Loaded assembly: /storage/emulated/0/Android/data/com.abdullah.extrony/files/.__override__/Microsoft.Azure.Mobile.dll [External]
Loaded assembly: /storage/emulated/0/Android/data/com.abdullah.extrony/files/.__override__/Microsoft.Data.Sqlite.dll [External]
Loaded assembly: /storage/emulated/0/Android/data/com.abdullah.extrony/files/.__override__/Microsoft.EntityFrameworkCore.dll [External]
Loaded assembly: /storage/emulated/0/Android/data/com.abdullah.extrony/files/.__override__/Microsoft.EntityFrameworkCore.Relational.dll [External]
Loaded assembly: /storage/emulated/0/Android/data/com.abdullah.extrony/files/.__override__/Microsoft.EntityFrameworkCore.Sqlite.dll [External]
Loaded assembly: /storage/emulated/0/Android/data/com.abdullah.extrony/files/.__override__/Microsoft.Extensions.Caching.Abstractions.dll [External]
Loaded assembly: /storage/emulated/0/Android/data/com.abdullah.extrony/files/.__override__/Microsoft.Extensions.Caching.Memory.dll [External]
Loaded assembly: /storage/emulated/0/Android/data/com.abdullah.extrony/files/.__override__/Microsoft.Extensions.DependencyInjection.Abstractions.dll [External]
Loaded assembly: /storage/emulated/0/Android/data/com.abdullah.extrony/files/.__override__/Microsoft.Extensions.DependencyInjection.dll [External]
Loaded assembly: /storage/emulated/0/Android/data/com.abdullah.extrony/files/.__override__/Microsoft.Extensions.Logging.Abstractions.dll [External]
Loaded assembly: /storage/emulated/0/Android/data/com.abdullah.extrony/files/.__override__/Microsoft.Extensions.Logging.dll [External]
Loaded assembly: /storage/emulated/0/Android/data/com.abdullah.extrony/files/.__override__/Microsoft.Extensions.Options.dll [External]
Loaded assembly: /storage/emulated/0/Android/data/com.abdullah.extrony/files/.__override__/Microsoft.Extensions.Primitives.dll [External]
Loaded assembly: /storage/emulated/0/Android/data/com.abdullah.extrony/files/.__override__/ModernHttpClient.dll [External]
Loaded assembly: /storage/emulated/0/Android/data/com.abdullah.extrony/files/.__override__/Newtonsoft.Json.dll [External]
Loaded assembly: /storage/emulated/0/Android/data/com.abdullah.extrony/files/.__override__/OkHttp.dll [External]
Loaded assembly: /storage/emulated/0/Android/data/com.abdullah.extrony/files/.__override__/Plugin.Connectivity.Abstractions.dll [External]
Loaded assembly: /storage/emulated/0/Android/data/com.abdullah.extrony/files/.__override__/Plugin.Connectivity.dll [External]
Loaded assembly: /storage/emulated/0/Android/data/com.abdullah.extrony/files/.__override__/Plugin.CurrentActivity.dll [External]
Loaded assembly: /storage/emulated/0/Android/data/com.abdullah.extrony/files/.__override__/Plugin.Settings.Abstractions.dll [External]
Loaded assembly: /storage/emulated/0/Android/data/com.abdullah.extrony/files/.__override__/Plugin.Settings.dll [External]
Loaded assembly: /storage/emulated/0/Android/data/com.abdullah.extrony/files/.__override__/Plugin.Share.Abstractions.dll [External]
Loaded assembly: /storage/emulated/0/Android/data/com.abdullah.extrony/files/.__override__/Plugin.Share.dll [External]
Loaded assembly: /storage/emulated/0/Android/data/com.abdullah.extrony/files/.__override__/Remotion.Linq.dll [External]
Loaded assembly: /storage/emulated/0/Android/data/com.abdullah.extrony/files/.__override__/SgmlReaderDll.dll [External]
Loaded assembly: /storage/emulated/0/Android/data/com.abdullah.extrony/files/.__override__/Splat.dll [External]
Loaded assembly: /storage/emulated/0/Android/data/com.abdullah.extrony/files/.__override__/System.Collections.Immutable.dll [External]
Loaded assembly: /storage/emulated/0/Android/data/com.abdullah.extrony/files/.__override__/System.Diagnostics.DiagnosticSource.dll [External]
Loaded assembly: /storage/emulated/0/Android/data/com.abdullah.extrony/files/.__override__/System.Interactive.Async.dll [External]
Loaded assembly: /storage/emulated/0/Android/data/com.abdullah.extrony/files/.__override__/System.Runtime.CompilerServices.Unsafe.dll [External]
Loaded assembly: /storage/emulated/0/Android/data/com.abdullah.extrony/files/.__override__/Xamarin.Android.Support.Animated.Vector.Drawable.dll [External]
Loaded assembly: /storage/emulated/0/Android/data/com.abdullah.extrony/files/.__override__/Xamarin.Android.Support.CustomTabs.dll [External]
Loaded assembly: /storage/emulated/0/Android/data/com.abdullah.extrony/files/.__override__/Xamarin.Android.Support.Design.dll [External]
Loaded assembly: /storage/emulated/0/Android/data/com.abdullah.extrony/files/.__override__/Xamarin.Android.Support.v4.dll [External]
Loaded assembly: /storage/emulated/0/Android/data/com.abdullah.extrony/files/.__override__/Xamarin.Android.Support.v7.AppCompat.dll [External]
Loaded assembly: /storage/emulated/0/Android/data/com.abdullah.extrony/files/.__override__/Xamarin.Android.Support.v7.CardView.dll [External]
Loaded assembly: /storage/emulated/0/Android/data/com.abdullah.extrony/files/.__override__/Xamarin.Android.Support.v7.MediaRouter.dll [External]
Loaded assembly: /storage/emulated/0/Android/data/com.abdullah.extrony/files/.__override__/Xamarin.Android.Support.v7.RecyclerView.dll [External]
Loaded assembly: /storage/emulated/0/Android/data/com.abdullah.extrony/files/.__override__/Xamarin.Android.Support.Vector.Drawable.dll [External]
Loaded assembly: /storage/emulated/0/Android/data/com.abdullah.extrony/files/.__override__/Xamarin.Forms.Core.dll [External]
Loaded assembly: /storage/emulated/0/Android/data/com.abdullah.extrony/files/.__override__/Xamarin.Forms.Platform.Android.dll [External]
Loaded assembly: /storage/emulated/0/Android/data/com.abdullah.extrony/files/.__override__/Xamarin.Forms.Platform.dll [External]
Loaded assembly: /storage/emulated/0/Android/data/com.abdullah.extrony/files/.__override__/Xamarin.Forms.Xaml.dll [External]
Loaded assembly: /storage/emulated/0/Android/data/com.abdullah.extrony/files/.__override__/extrony.dll
Loaded assembly: /storage/emulated/0/Android/data/com.abdullah.extrony/files/.__override__/extrony.Data.dll
Loaded assembly: Mono.Android.dll [External]
Loaded assembly: Java.Interop.dll [External]
Loaded assembly: System.Runtime.dll [External]
Loaded assembly: System.Collections.Concurrent.dll [External]
Loaded assembly: System.Reflection.dll [External]
Loaded assembly: System.Threading.dll [External]
Loaded assembly: System.Diagnostics.Debug.dll [External]
Loaded assembly: System.dll [External]
Loaded assembly: System.Runtime.InteropServices.dll [External]
Loaded assembly: System.Collections.dll [External]
Loaded assembly: System.Linq.dll [External]
Loaded assembly: System.Core.dll [External]
Loaded assembly: System.Reflection.Extensions.dll [External]
Loaded assembly: MonoDroidConstructors [External]
Loaded assembly: System.ObjectModel.dll [External]
Loaded assembly: System.Threading.Tasks.dll [External]
Loaded assembly: System.Xml.ReaderWriter.dll [External]
Loaded assembly: System.Xml.dll [External]
Loaded assembly: System.IO.dll [External]
Loaded assembly: System.Runtime.Extensions.dll [External]
Loaded assembly: System.Linq.Expressions.dll [External]
Loaded assembly: System.Resources.ResourceManager.dll [External]
Loaded assembly: System.Globalization.dll [External]
Loaded assembly: System.Dynamic.Runtime.dll [External]
Loaded assembly: System.ComponentModel.dll [External]
Thread started: <Thread Pool> #2
Thread started: <Thread Pool> #3
Thread started: <Thread Pool> #4
Thread started: <Thread Pool> #5
Loaded assembly: System.Linq.Queryable.dll [External]
Loaded assembly: Anonymously Hosted DynamicMethods Assembly [External]
Loaded assembly: System.Data.Common.dll [External]
Loaded assembly: System.Data.dll [External]
Thread started: <Thread Pool> #6
Loaded assembly: System.Diagnostics.Tracing.dll [External]
Loaded assembly: System.ComponentModel.Annotations.dll [External]
Loaded assembly: System.ComponentModel.DataAnnotations.dll [External]
EDIT 3: Tested on different devices per suggestion received via comments. These are the results (from a release build)
Edit 4: I have done a very detailed testing and I can confirm that "context.Migrate() and a simple query with SingleOrDefault()" (EFCore) takes 9 seconds. If I remove this call, the app starts in ~3 seconds.
EDIT 5: I was expecting to do the db init on a different thread in the splash activity (like the below), since the Xamarin.Forms initialization (usually) takes around 3 seconds and I want the init also to happen in parallel. However it appears that even though it runs on a different thread the EFCore db init also contributes to the start-up time. Am I doing anything wrong?
protected override void OnResume()
{
base.OnResume();
System.Threading.Tasks.Task.Run(() =>
{
App.DbFolder = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal);
App.InitializeDb();
});
StartActivity(typeof(MainActivity));
}
Any help with a suggestion?
Upvotes: 7
Views: 2411
Reputation: 1666
If your Main Page calls services , loads data or does something that needs some time to complete, you can add splash screen . This is solve my problem on android.
Upvotes: -1
Reputation: 16199
4.5 Seconds is being taken up by this section, if this is an accurate representation of when the app finishes loading.
04-01 07:53:15.443 D/Mono ( 1742): [0x9ac5e930] hill climbing, change max number of threads 2
04-01 07:53:15.445 W/art ( 1742): JNI RegisterNativeMethods: attempt to register 0 native methods for md54ada4fbe4a5955f6151fa282d30cfc48.SelfDisposingBitmapDrawable
Resolved pending breakpoint at 'CleanUpReceiver.cs:16,1' to void extrony.Droid.Receivers.CleanUpReceiver.OnReceive (Android.Content.Context context, Android.Content.Intent intent) [0x00000].
04-01 07:53:20.059 D/Mono ( 1742): DllImport searching in: '/system/lib/libsqlite.so' ('/system/lib/libsqlite.so').
04-01 07:53:20.059 D/Mono ( 1742): Searching for 'sqlite3_column_count'.
Everything is loaded at this point, hence it's something in your code, most likely in the App.xaml.cs constructor. I notice you also have EF Core as well.
There could be many things going on here, but until App.xaml.cs is completed, it will still show the splashscreen.
I would recommend adding a StopWatch in parts of your code on startup and see what is taking the time. From there you could ask a different question in stackoverflow relating that problem.
System.Diagnostics.Stopwatch s = new System.Diagnostics.Stopwatch();
s.Start();
// Code in here
s.Stop();
System.Diagnostics.Debug.WriteLine($"Elapsed Time: {s.ElapsedMilliseconds.ToString("N0")}");
Upvotes: 4