启动屏幕活动会强制我的设备重新启动

时间:2017-03-26 14:56:48

标签: c# android xamarin android-appcompat splash-screen

我正在查看关于 Xamarin 的文章,该文章指导我们如何在 AppCompatActivity 上添加启动画面。每当我运行应用程序时,它都会强制我的设备重新启动。

以下是我为解决问题所做的工作,但我失败了。

  1. 将Java最大堆大小设置为1G
  2. 正确按照Xamarin article上列出的步骤创建启动画面
  3. 正确安装了AppCompatv7和v4支持
  4. 问题仍然存在。 这是我的代码也许我在编码部分做错了。

    启动活动

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using Android.App;
    using Android.Content;
    using Android.OS;
    using Android.Runtime;
    using Android.Support.V7.App;
    using Android.Views;
    using Android.Widget;
    
    namespace TestApp
    {
        [Activity(Label = "SplashActivity", MainLauncher = true, NoHistory = true, Theme = "@style/MyTheme.Splash")]
        public class SplashActivity : AppCompatActivity
        {
            protected override void OnCreate(Bundle savedInstanceState)
            {
                base.OnCreate(savedInstanceState);
    
                // Create your application here
                var startupTask = new Task(SimulateStartup);
                startupTask.Start();
    
            }
            private async void SimulateStartup()
            {
                await Task.Delay(4000);
                var intent = new Intent(this, typeof(MainActivity));
                intent.AddFlags(ActivityFlags.ClearTop | ActivityFlags.NewTask);
                StartActivity(intent);
            }
        }
    }
    

    MainActivity

    using System.Threading.Tasks;
    using Android.App;
    using Android.Widget;
    using Android.OS;
    using Android.Support.V7.App;
    using System;
    using Android.Content;
    
    namespace TestApp
    {
        [Activity(Label = "MainActivity")]
        public class MainActivity : AppCompatActivity
        {
            protected override void OnCreate(Bundle bundle)
            {
                base.OnCreate(bundle);
    
                // Set our view from the "main" layout resource
                SetContentView (Resource.Layout.Main);
            }
    
    
        }
    }
    

    Styles.xml

    <?xml version="1.0" encoding="utf-8" ?>
    <resources>
      <style name="MyTheme.Base" parent="Theme.AppCompat.Light">
      </style>
    
      <style name="MyTheme" parent="MyTheme.Base">
    
      </style>
    
      <style name="MyTheme.Splash" parent="Theme.AppCompat.Light.NoActionBar">
        <item name="android:windowBackground">@drawable/splash_screen</item>
        <item name="android:windowNoTitle">true</item>
        <item name="android:windowFullscreen">true</item>
      </style>
    </resources>
    

    splash_screen.xml

    <?xml version="1.0" encoding="utf-8" ?> 
    <layer-list xmlns:android="http://schemas.android.com/apk/res/android">
      <item>
        <color android:color="@color/splash_background"/>
      </item>
      <item>
        <bitmap android:src="@drawable/splash" android:tileMode="disabled" android:gravity="center" /> 
      </item>
    </layer-list>
    

    colors.xml

    <?xml version="1.0" encoding="utf-8" ?>
    <resources>
      <color name="primary">#4682b4</color>
      <color name="primaryDark">#2c6493</color>
      <color name="accent">#FFC107</color>
      <color name="window_background">#F5F5F5</color>
      <color name="splash_background">#4682b4</color>
    </resources>
    

1 个答案:

答案 0 :(得分:1)

请检查您的位图大小。如果它太大,可能会导致重启:请参阅Xamarin Android App causes device reboot