C# 将url从Activity1加载到包含Web视图的Activity2

C# 将url从Activity1加载到包含Web视图的Activity2,c#,android,url,webview,xamarin,C#,Android,Url,Webview,Xamarin,如何将url从firstActivity加载到webpageActivity? 我希望能够从firstActivity中单击带有url的按钮,然后将其传递到网页活动并加载url 这是我的代码:FirstActivity 创建时受保护的覆盖无效(捆绑包) { base.OnCreate(bundle) //从“主”布局资源设置视图 SetContentView(Resource.Layout.Main); //从布局资源中获取我们的按钮, //并在其上附加一个事件 var scisnews=fin

如何将url从firstActivity加载到webpageActivity? 我希望能够从firstActivity中单击带有url的按钮,然后将其传递到网页活动并加载url

这是我的代码:FirstActivity

创建时受保护的覆盖无效(捆绑包) { base.OnCreate(bundle)

//从“主”布局资源设置视图
SetContentView(Resource.Layout.Main);
//从布局资源中获取我们的按钮,
//并在其上附加一个事件
var scisnews=findviewbyd(Resource.Id.scisnewsbtn);
字符串scisnewsurl=”http://cis.ulster.ac.uk/news-a-events-mainmenu-70";
//标签导入。单击+=(发件人,e)=>{
//var LABICTIONI=新意图(此,类型为(LABICTION));
//星触觉(LAB);
//};
scisnews.Click+=委托{
var ScisNewsI=新意图(此,类型为(网页));
ScisNewsI.PutExtra(“scisnews”,scisnewsurl);
这是一种新的触觉(ScisNewsI);
};
}
公共类HelloWebViewClient:WebViewClient
{
公共重写bool ShouldOverrideUrlLoading(WebView视图,字符串url)
{
view.LoadUrl(“http://cis.ulster.ac.uk/news-a-events-mainmenu-70");
返回true;
}
}
}
代码:WebPageActivity

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

        // Create your application here
        SetContentView (Resource.Layout.WebPageLO);

        web_view = FindViewById<WebView> (Resource.Id.webview);

        web_view.Settings.JavaScriptEnabled = true;
        web_view.Settings.BuiltInZoomControls = true;




        web_view.SetWebViewClient (new HelloWebViewClient ());



    }
}


public class HelloWebViewClient : WebViewClient
{
    public override bool ShouldOverrideUrlLoading (WebView view, string url)
    {
        view.LoadUrl ("http://cis.ulster.ac.uk/news-a-events-mainmenu-70");
        return true;
    }
}


public override bool OnKeyDown (Android.Views.Keycode keyCode, Android.Views.KeyEvent e)
{
    if (keyCode == Keycode.Back && web_view.CanGoBack ()) 
    {
        web_view.GoBack ();
        return true;
    }

    return base.OnKeyDown (keyCode, e);
}
protectedoverride void OnCreate(捆绑包)
{
base.OnCreate(bundle);
//在此处创建应用程序
SetContentView(Resource.Layout.WebPageLO);
web_view=findviewbyd(Resource.Id.webview);
web_view.Settings.JavaScriptEnabled=true;
web_view.Settings.BuiltInZoomControls=true;
web_view.SetWebViewClient(新的HelloWebViewClient());
}
}
公共类HelloWebViewClient:WebViewClient
{
公共重写bool ShouldOverrideUrlLoading(WebView视图,字符串url)
{
view.LoadUrl(“http://cis.ulster.ac.uk/news-a-events-mainmenu-70");
返回true;
}
}
公共覆盖bool OnKeyDown(Android.Views.Keycode-Keycode,Android.Views.KeyEvent e)
{
if(keyCode==keyCode.Back&&web\u view.CanGoBack())
{
web_view.GoBack();
返回true;
}
返回base.OnKeyDown(keyCode,e);
}

}

您通常使用
Intent
类将信息从一个活动传递到另一个活动。看起来您正在尝试,但没有代码提取值

以下是一个例子:

//In your first activity
var intent = new Intent(this, typeof(WebPage));
intent.PutExtra("url", "http://cis.ulster.ac.uk/news-a-events-mainmenu-70");
StartActivity(intent);

//Then in the second activity
string url = Intent.GetStringExtra("url");

//Then you can load the page like this
web_view.LoadUrl(url);

这有帮助吗?

我的下一个问题是,我如何覆盖它,以便在单击另一个按钮时,例如我从第一个活动添加另一个url,我希望它加载不同的url,但在同一网页活动中?e、 g.“var intent2=新意图(此,类型为(网页));intent.PutExtra(“url2”、“google.com”);星触觉(意图2);'那么第二个活动我要做什么?我让它工作了。非常感谢你的帮助
//In your first activity
var intent = new Intent(this, typeof(WebPage));
intent.PutExtra("url", "http://cis.ulster.ac.uk/news-a-events-mainmenu-70");
StartActivity(intent);

//Then in the second activity
string url = Intent.GetStringExtra("url");

//Then you can load the page like this
web_view.LoadUrl(url);