2012-07-10 41 views
0

我有一個小的iOS應用程序(寫入使用monotouch),我想要引入monodroid。該端口引發了一些問題,其中一些問題與兩個平臺關於UI的方式以及圍繞它們創建類相關。從monotouch移動monodroid - 異步和線程移植

在iOS應用中有這樣

private void BtnSomething_TouchUpInside (object sender, EventArgs e) 
    { 
     string f = this.foo; 
        LGPM gpm = new LGPM(Constants.a, Constants.b, f); 
     this.auth = new Auth("cheese", gpm); 
    (*) this.auth.TokenReceived += (o, e, a, aTS, r) => { 
        // more stuff here 
     }; 

     this.PresentModalViewController(this.auth, true); 
    } 

在auth類看起來像這樣

public partial class Auth 
{ 
    public Auth(string m, data d) 
    { 
     this.d = d; 
     this.m = m; 
    } 

// create a UIWebView and do things 

結果碼 - 身份驗證創建web視圖,做事並把控制返回到(* )線

對於monodroid,事情是不同的,因爲你不能真正創建類。我想出的最好的是這個

private void BtnSomething_TouchUpInside (object sender, EventArgs e) 
    { 
     string f = this.foo; 
        LGPM gpm = new LGPM(Constants.a, Constants.b, f); 
     this.auth = new Auth("cheese", gpm, context); 
    (*) this.auth.TokenReceived += (o, e, a, aTS, r) => { 
        // more stuff here 
     }; 

     this.PresentModalViewController(this.auth, true); 
    } 

然後在驗證類

public class Auth : Application 
{ 
    public Auth(string m, data d, Context c) 
    { 
     this.d = d; 
     this.m = m; 
     Intent t = new Intent(this, typeof(webview)); 
     t.PutExtra("todo", 1); 
     c.StartActivity(t); 
    } 
} 

[Activity] 

這是再「正常」的網頁流量的活動。

這似乎工作,但是,一旦webview完成,控制不會返回到(*)行。

webview本身正在執行從網站(稱爲AuthToken)的異步數據抓取,這會導致事件在完成後拋出。我不確定這兩者之間的差異是如何寫入類和活動的,但在iOS版本中,事件被觸發,在Android版本中,它被錯過了。

這使我想知道平臺在處理異步事件方面是否有所不同。是否有教程介紹兩種平臺如何處理異步事件?

我知道很多問題,但線程和異步事件很重要。

感謝

回答

0

使用startActivityForResult或其他Android主義得到一些處理事件後的線程。