2017-02-11 13 views
3

呼び出されていない私は、一緒にMvvmCross.Formsと私の既存のXamarin.Formsアプリケーションを置くしようとしています。残念ながら私は初期化を行うことができません。MvvmCross:セットアップ

MainActivity.cs

[Activity(MainLauncher = true, Label = "Main Activity")] 
public class MainActivity : FormsApplicationActivity 
{ 
    protected override void OnCreate(Bundle bundle) 
    { 
     base.OnCreate(bundle); 

     Forms.Init(this, bundle); 
     var app = new MvxFormsApp(); 
     LoadApplication(app); 

     var presenter = (MvxFormsDroidPagePresenter) Mvx.Resolve<IMvxViewPresenter>(); // Exception 
     presenter.MvxFormsApp = app; 

     Mvx.Resolve<IMvxAppStart>().Start(); 
    } 
} 

Setup.cs

public class Setup : MvxAndroidSetup 
{ 
    public Setup(Context applicationContext) : base(applicationContext) 
    { 
    } 

    protected override IMvxApplication CreateApp() 
    { 
     return new App(); 
    } 

    protected override IMvxAndroidViewPresenter CreateViewPresenter() 
    { 
     var presenter = new MvxFormsDroidPagePresenter(); 
     Mvx.RegisterSingleton<IMvxViewPresenter>(presenter); 
     return presenter; 
    } 
} 

私は問題がないとしても、コンストラクタ、セットアップが全く呼び出されていないということですね。私は正しい?コードの何が間違っていますか?

答えて

2

スプラッシュ画面でブートストラップが行われます。で物事をシンプルに保つために https://github.com/xabre/xamarin-bluetooth-le/tree/master/Source/BLE.Client

+0

:あなたが作業の例が必要な場合は、私たちの例のアプリを参照してください

[Activity(MainLauncher = true , Theme = "@style/Theme.Splash" , NoHistory = true , ScreenOrientation = ScreenOrientation.Portrait)] public class SplashScreen : MvxSplashScreenActivity { public SplashScreen() : base(Resource.Layout.SplashScreen) { } private bool _isInitializationComplete; public override void InitializationComplete() { if (!_isInitializationComplete) { _isInitializationComplete = true; StartActivity(typeof(MainActivity)); } } protected override void OnCreate(Android.OS.Bundle bundle) { Forms.Init(this, bundle); Forms.ViewInitialized += (object sender, ViewInitializedEventArgs e) => { if (!string.IsNullOrWhiteSpace(e.View.StyleId)) { e.NativeView.ContentDescription = e.View.StyleId; } }; base.OnCreate(bundle); } } 

:あなたはあなたのMainActivityからMainLauncher = trueを削除し、同様にスプラッシュ画面を追加する必要が

私はスプラッシュスクリーンを避けました:-)このプロジェクトは、私が一歩進んでいっても助けになりました。 Dankeschön:-) – core

+0

MvvmCross 5.0では、スプラッシュスクリーンのないブートストラップがサポートされるかもしれません。 –