Professional Documents
Culture Documents
I have been trying to find a way that can be used to detect a specific URL in a WebView and then
start another Activity. Following is the code:
C# Expand ▼
{
view.LoadUrl(url);
return true;
progressDialog.Show();
if(url=="http://test-domain.com")
StartActivity(typeof(MainActivity));
base.OnPageFinished(view, url);
But I know StartActivity cannot be used in WebViewClient as I get the following error "An object
reference is required for the non-static field, method or property 'Context.StartActivity(Type)'".
Can Anyone please guide me with the solution?
https://www.codeproject.com/Questions/1193425/Detect-specific-URL-and-change-activity 1/4
9/10/22, 3:06 PM Detect specific URL and change activity - CodeProject
I have tried getting url of the webview with "string url= webView.URL;" but again i get stuck at
how to start another activity.
Add a Solution
1 solution
Solution 1
I was able to solve it by making following changes to the class:
C# Expand ▼
this.context = context;
view.LoadUrl(url);
return true;
progressDialog.Show();
if (url.Equals("https://test.com/"))
context.StartActivity(intent);
C#
webView.SetWebViewClient(new ClientWebView(this));
https://www.codeproject.com/Questions/1193425/Detect-specific-URL-and-change-activity 2/4
9/10/22, 3:06 PM Detect specific URL and change activity - CodeProject
Preview
…
https://www.codeproject.com/Questions/1193425/Detect-specific-URL-and-change-activity 3/4
9/10/22, 3:06 PM Detect specific URL and change activity - CodeProject
3. If a question is poorly phrased then either ask for clarification, ignore it, or
edit the
question and fix the problem. Insults are not welcome.
4. Don't tell someone to read the manual. Chances are they have and don't get it.
Provide
an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.
This content, along with any associated source code and files, is licensed under The Code Project Open License
(CPOL)
Terms of Use
Web04
2.8:2022-09-02:1
Last Updated 8 Sep 2022
CodeProject,
20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8
+1 (416) 849-8900
https://www.codeproject.com/Questions/1193425/Detect-specific-URL-and-change-activity 4/4