Forum Xamarin.Forms

Announcement:

The Xamarin Forums have officially moved to the new Microsoft Q&A experience. Microsoft Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

To create new threads and ask questions head over to Microsoft Q&A for .NET and get involved today.

Problem with animated splash with Xamarin.Forms on Android

Hi, I'm making an animated splash with this tutorial and after instalation app crashes and I don't even know why. Can someone help me with this? My code:

MainActivity:
`namespace testApp2.Droid
{
[Activity(Label = "Simple Test", Theme = "@style/Theme.Splash", Icon = "@drawable/icon", MainLauncher = false, NoHistory = true)]

 public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsApplicationActivity
{
    protected override void OnCreate (Bundle bundle)
    {
        base.OnCreate (bundle);

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

}`

SplashActivity:
`namespace testApp2.Droid
{
[Activity(Theme = "@style/Theme.Splash", Icon = "@drawable/icon", MainLauncher = true, NoHistory = true)]
public class SplashActivity : Activity
{

    private void LoadActivity()
    {
        System.Threading.Thread.Sleep(5000); // Simulate a long pause    
        RunOnUiThread(() => StartActivity(typeof(MainActivity)));
    }

    public override void OnWindowFocusChanged(bool hasFocus)
    {
        ImageView imageView = FindViewById<ImageView>(Resource.Id.animated_loading);

        Android.Graphics.Drawables.AnimationDrawable animation = (Android.Graphics.Drawables.AnimationDrawable)imageView.Drawable;

        animation.Start(); //lel
    }

    protected override void OnCreate(Bundle bundle)
    {
        base.OnCreate(bundle);

        SetContentView(Resource.Layout.SplashLayout);
        System.Threading.ThreadPool.QueueUserWorkItem(o => LoadActivity());
    }
}

}`

SplashLayout.xaml:
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" android:minWidth="25px" android:minHeight="25px" android:gravity="center"> <ImageView android:id="@+id/animated_loading" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:src="@anim/loadinganimation" /> </LinearLayout>

Styles.xml:
<?xml version="1.0" encoding="utf-8" ?> <resources> <style name="Theme.Splash" parent="android:Theme.Holo.Light.NoActionBar.Fullscreen"> <item name="android:colorBackground">@android:color/white</item> <item name="android:windowNoTitle">true</item> </style> </resources>

LoadingAnimation.xml:
<?xml version="1.0" encoding="utf-8" ?> <animation-list xmlns:android="http://schemas.android.com/apk/res/android" android:oneshot="false"> <item android:drawable="@drawable/img00031" android:duration="112"/> <item android:drawable="@drawable/img00030" android:duration="112"/> <item android:drawable="@drawable/img00029" android:duration="112"/> <item android:drawable="@drawable/img00028" android:duration="112"/> <item android:drawable="@drawable/img00027" android:duration="112"/> <item android:drawable="@drawable/img00026" android:duration="112"/> <item android:drawable="@drawable/img00025" android:duration="112"/> <item android:drawable="@drawable/img00024" android:duration="112"/> <item android:drawable="@drawable/img00023" android:duration="112"/> <item android:drawable="@drawable/img00022" android:duration="112"/> <item android:drawable="@drawable/img00021" android:duration="112"/> <item android:drawable="@drawable/img00020" android:duration="112"/> <item android:drawable="@drawable/img00019" android:duration="112"/> <item android:drawable="@drawable/img00018" android:duration="112"/> <item android:drawable="@drawable/img00017" android:duration="112"/> <item android:drawable="@drawable/img00016" android:duration="112"/> <item android:drawable="@drawable/img00015" android:duration="112"/> <item android:drawable="@drawable/img00014" android:duration="112"/> <item android:drawable="@drawable/img00013" android:duration="112"/> <item android:drawable="@drawable/img00012" android:duration="112"/> <item android:drawable="@drawable/img00011" android:duration="112"/> <item android:drawable="@drawable/img00010" android:duration="112"/> <item android:drawable="@drawable/img00009" android:duration="112"/> <item android:drawable="@drawable/img00008" android:duration="112"/> <item android:drawable="@drawable/img00007" android:duration="112"/> <item android:drawable="@drawable/img00006" android:duration="112"/> <item android:drawable="@drawable/img00005" android:duration="112"/> <item android:drawable="@drawable/img00004" android:duration="112"/> <item android:drawable="@drawable/img00003" android:duration="112"/> <item android:drawable="@drawable/img00002" android:duration="112"/> <item android:drawable="@drawable/img00001" android:duration="112"/> </animation-list>

Sign In or Register to comment.