当我的应用程序从设备启动时,为什么我的Android启动画面没有执行?

时间:2016-10-04 00:04:19

标签: c# android xamarin.android

从我的IDE执行时,我的启动画面活动运行得很好,但是当我从移动设备启动应用程序时,它无法显示启动画面活动。

启动活动:

namespace ICA_Deliveries
{
[Activity(Label = "ICA Deliveries", MainLauncher = true, NoHistory = true, Icon = "@drawable/icaswift")]
public class Splash : Activity
{
    protected override void OnCreate(Bundle savedInstanceState)
    {
        base.OnCreate(savedInstanceState);

        RequestWindowFeature(WindowFeatures.NoTitle);

        // Set our view from the "Splash" layout resource
        SetContentView(Resource.Layout.Splash);       

    }

    protected override void OnResume()
     {
         base.OnResume();

         Task startupWork = new Task(() => {             
             Task.Delay(1000);  // Simulate a bit of startup work               
         }); 

         startupWork.ContinueWith(t => {
             Task.Delay(3000).Wait();
             StartActivity(new Intent(this, typeof(MainActivity)));
         }, TaskScheduler.FromCurrentSynchronizationContext()); 

         startupWork.Start(); 
     }       
   }
}

1 个答案:

答案 0 :(得分:1)

我遇到同样的问题,因为有些设备无法正常工作。
  从代码中删除任务相关代码并使用Handler等待一段时间并转到下一个屏幕。
以下代码对我有用。

public class SplashActivity : Activity
{


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

        SetContentView (Resource.Layout.splash);

        Handler handler = new Handler ();
        handler.PostDelayed (gotoMainActivity, 1000);

    }

    public void gotoMainActivity ()
    {

            var intent = new Intent (this, typeof (MainActivity));
            StartActivity (intent);
            Finish ();

    }
}