Unlock Activity jump: Use scheme jump, activityscheme
Activity jump is very simple. to jump from one page to another, we usually use the following:
Intent intent = new Intent(this, xxx.class);startActivity(intent);
Of course, we also use implicit redirection to specify
Action
Intent intent = new Intent("this is an action");startActivity(intent);
Neither of the two mentioned in this article is mentioned. Here we use the scheme protocol for page Jump.
Manifest/data configurationConfiguration in AndroidManifest (this is probably the principle when you click an advertisement when browsing the Web page)
The above code is just a simple configurationAndroid: scheme attribute. It is so easy to open this Activity.
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("azhon.scheme://")));
Of course, you can also configure more attributes in <data/> (from the official Chinese document, you can click the manifest/data configuration above)
Scheme path rules
:// : [ | | ]
Start with scheme: // host name: Port Number/[path/parameter] The concatenation parameter after the path is also available for use below.
This address is almost the same as the web address we often use.
Open the corresponding page on the webpage
We modified the Activity configuration in Manifest to add more materials. Here we created two pages.
Add a WebView control in the homepage layout and load itCode of the html file layout file in the assets Folder:
Html code in the assets Folder:
Jump to TestOneActivity
Jump to TestTwoActivity
:
In the web page, you only need to use a hyperlink to easily jump to our app, is it very happy.
When you view the html file in the browser of your mobile phone, you can click the file to jump to the app.
When you jump to a page, you can still go through? Key = value & key1 = value2 key-value Pair Mode concatenates parameters following the address
Receive the passed parameters on the previous page.
Intent intent = getIntent();Uri uri = intent.getData();assert uri != null;sb.append("scheme: ").append(intent.getScheme()).append("
"); sb.append("host: ").append(uri.getHost()).append("
"); sb.append("port: ").append(uri.getPort()).append("
"); sb.append("path: ").append(uri.getPath()).append("
"); sb.append("params: ").append(uri.getQuery()).append("
"); // Get the key name Set with all parameters Names = uri. getQueryParameterNames (); Iterator Iterator = names. iterator (); while (iterator. hasNext () {String key = iterator. next (); sb. append (key ). append (":"). append (uri. getQueryParameter (key )). append ("
"); } tv.setText(Html.fromHtml(sb.toString()));
With this jump method, you only need to know the scheme of other apps, And you can jump over and think about it at will. For example, the following code opens and QQ programs.
Open
Open QQ
: