2016-09-09 7 views
0

AndroidおよびiOS用のXamarin.Formsアプリケーションを使用してqrコードを読み取り、それをローカルのsqliteデータベースに保存しました。特定のデバイスでXamarin.Formsメソッドを2回実行する

アプリは3つのデバイス(iOS 9.3.5のiPhone 4、iOS 9.4のiPhone 5、Android 6.0のSamsung Galaxy S7 Edge)にインストールされます。奇妙なことに、iPhone 4のバーコードの方法では、データベースに保存するために2回呼ばれています!

Device.BeginInvokeOnMainThread(() =>{ 
         Navigation.PopAsync(); 
         DisplayAlert("Scanned Barcode", result.Text, "OK"); 
         dbHelper.SaveItem(new DbItem() { Name = result.Text }); 
    }); 

答えて

1

あなたがイベントをロックするためのフラグを使用することができますのようなもの:あなたは `フラグを追加することができます

Device.BeginInvokeOnMainThread(() =>{ 

    if(flag){ 
     return; 
    } 

    flag = true; 

    Navigation.PopAsync(); 
    DisplayAlert("Scanned Barcode", result.Text, "OK"); 
    dbHelper.SaveItem(new DbItem() { Name = result.Text }); 
}); 

override OnAppearing(){ 
    flag = false; 
} 
+1

= falseは、' 'dbHelper.SaveItem(新DbItem(){名前= result.Text後}); '再びロックを解除する。 – hvaughan3

関連する問題