Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Analysis of the operation mechanism of Android WeChat Mini Programs development

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly explains "analyzing the operating mechanism of Android WeChat Mini Programs development". The content of the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "analyzing the operating mechanism of Android WeChat Mini Programs development".

We call the environment provided by Wechat clients to Mini Program as the hosting environment. With the help of the capabilities provided by the host environment, Mini Program can accomplish many functions that ordinary web pages cannot do.

02 render layer and logical layer

Wxml,wxss works at the render layer, and JS scripts work at the logical layer. The render layer and logic layer of Mini Program are managed by 2 threads respectively:

The interface of the render layer uses WebView to render; Mini Program usually has multiple pages, so there are multiple WebView threads in the render layer.

The logic layer uses JsCore threads to run JS scripts.

The communication between threads is transferred by Native (Wechat client).

03, programs and pages

The Wechat client downloads the entire Mini Program code package locally before opening it.

Then you can know all the page paths of your current Mini Program through the pages field of app.json:

{"pages": ["pages/index/index",-- first page "pages/logs/logs"]}

After Mini Program starts, the onLaunch callback of the App instance defined by app.js will be executed.

There is only one App instance for the whole Mini Program, which is shared by all pages.

Next, let's take a brief look at how a page on Mini Program is written.

You can observe that there are actually four kinds of files under pages/logs/logs.

Logs.json,logs.wxml, logs.wxss, logs.js

The Wechat client will first generate an interface according to the logs.json configuration, and the top color and text can be defined in this json file. The client will then load the WXML structure and WXSS style of the page. Finally, the client loads the logs.js, and you can see that the general content of the logs.js is:

Page ({data: {/ / data participating in page rendering logs: []}, onLoad: function () {/ / execution}} after page rendering)

Page is a page constructor that generates a page. When the page is generated, the Mini Program framework renders the data data with index.wxml to render the final structure, so you get what Mini Program looks like.

After rendering the interface, the page instance will receive an onLoad callback in which you can process your logic.

04, components and API

Mini Program provides a wealth of components, such as

In order to make it convenient for developers to call up the capabilities provided by Wechat, such as obtaining user information, WeChat Pay, etc., Mini Program provides a lot of API for developers to use

It is important to note that most API callbacks are asynchronous, and you need to deal with the async of code logic.

such as,

To get the user's geographic location, simply:

Wx.getLocation ({type: 'wgs84', success: (res) = > {var latitude = res.latitude / / Latitude var longitude = res.longitude / / Longitude}})

To call Wechat to scan the ability, you only need to:

Wx.scanCode ({success: (res) = > {console.log (res)}}) Thank you for your reading. The above is the content of "analyzing the operating mechanism of the development of Android WeChat Mini Programs". After the study of this article, I believe you have a deeper understanding of the problem of analyzing the operating mechanism of the development of Android WeChat Mini Programs, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report