In my app at the moment, I have a splash screen that shows a logo with as the app starts up.
I am making a free version of the app, and want to have a modified splash screen for that version. The way I manage the splash screen is to make a custom startup activity that then calls the main application activity after displaying the screen.
The problem I am having is that for some reason I am getting an exception that says several things.
Android.Content.Res.Resources+NotFoundException: File res/layout/scaledsplash.xml from drawable resource ID #0x7f0c00b7 ---> Android.Views.InflateException: Class not found ImageView ---> Java.Lang.ClassNotFoundException: Didn't find class "ImageView" on path: DexPathList
I have tried cleaning, and even scrubbing the obj folders, but it seems it's something more than an incorrect resource id in a precompiled file.
Here is the code I have
SplashActivity.cs
[Activity(NoHistory = true,
Theme = "@style/SplashScreen",
MainLauncher = true)]
public class SplashActivity : FormsAppCompatActivity
{
protected override async void OnCreate(Bundle savedInstanceState)
{
try
{
base.OnCreate(savedInstanceState);
this.SetContentView(Resource.Layout.ScaledSplash);
ImageView image = FindViewById<ImageView>(Resource.Id.ScaledSplashImage);
#if FREE_VER
image.SetImageResource(Resource.Drawable.FreeAppIconV2);
#else
image.SetImageResource(Resource.Drawable.AppIconV2);
#endif
//Build the database if needed, and populate the starting data set if necessary
await DBHelper.CreateDBTables().ConfigureAwait(true);
await DBHelper.InitDBStore().ConfigureAwait(true);
//Give the splash screen a few seconds to show before continuing on.
await Task.Delay(TimeSpan.FromSeconds(5d)).ConfigureAwait(true);
//Star the main app.
await InitMainApp();
}
catch (Exception ex)
{
Console.WriteLine($"SplashActivity.cs->Main()->{ex.Message}{System.Environment.NewLine}{ex.InnerException}{System.Environment.NewLine}{ex.StackTrace}");
}
}
private async Task InitMainApp()
{
StartActivity(typeof(MainActivity));
}
values/Styles.xml
<style name="SplashScreen" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowBackground">@layout/ScaledSplash</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowIsFloating">true</item>
<item name="android:backgroundDimEnabled">true</item>
</style>
layout/ScaledSplash.xml
<ImageView
xmlns:android="http://schemas.android.com/apk/res/android"
android:gravity="center"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/ScaledSplashImage"
android:contentDescription="ImagePane"
/>
Here is the main activity to start the main app once the splash screen is done showing.
MainActivity.cs
[Activity(Label = "ShootersToolbox", Icon = "@drawable/AppIconSM",
Theme = "@style/MainTheme",
LaunchMode = LaunchMode.SingleInstance,
MainLauncher = false,
WindowSoftInputMode = SoftInput.AdjustPan,
ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]
public class MainActivity : FormsAppCompatActivity
{
#region Methods
public override void OnRequestPermissionsResult(int requestCode, string[] permissions, [GeneratedEnum] Permission[] grantResults)
{
Xamarin.Essentials.Platform.OnRequestPermissionsResult(requestCode, permissions, grantResults);
base.OnRequestPermissionsResult(requestCode, permissions, grantResults);
//Added for the camera API
Plugin.Permissions.PermissionsImplementation.Current.OnRequestPermissionsResult(requestCode, permissions, grantResults);
}
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
AppDomain.CurrentDomain.UnhandledException += CurrentDomainOnUnhandledException;
TaskScheduler.UnobservedTaskException += TaskSchedulerOnUnobservedTaskException;
TabLayoutResource = Resource.Layout.Tabbar;
ToolbarResource = Resource.Layout.Toolbar;
Rg.Plugins.Popup.Popup.Init(this);
Xamarin.Forms.Forms.Init(this, savedInstanceState);
DisplayCrashReport();
MobileAds.Initialize(ApplicationContext);
Xamarin.Forms.FormsMaterial.Init(this, savedInstanceState);
Syncfusion.XForms.Android.PopupLayout.SfPopupLayoutRenderer.Init();
CrossCurrentActivity.Current.Init(this, savedInstanceState);
Xamarin.Essentials.Platform.Init(this, savedInstanceState);
LoadApplication(new App());
}
#endregion Methods
#region _r8 linker bug_
/// <summary>
/// Repairs problem with r8 linker not linking in these API functions...
/// </summary>
private const bool falseflag = true;
private static void LinkerPleaseInclude()
{
if (falseflag)
{
_ = new ButtonBarLayout(null, null);
_ = new FitWindowsFrameLayout(null);
_ = new AlertDialogLayout(null);
_ = new DialogTitle(null);
}
}
#endregion _r8 linker bug_
}
}
Any ideas or pointers most appreciated!!
Cheers!