2012-07-10 38 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主义得到一些处理事件后的线程。