Golang Mobile Application Example Example/basic Source framework Analysis

Source: Internet
Author: User
This is a creation in Article, where the information may have evolved or changed.

Conditional compilation

We can see 2 files in the source code: Main.go and Main_x.go the package main, both of which have the main function. Doesn't conflict?

The answer is no,

There is a comment in the Main_x.go file:

+build!darwin,!linux,!windows

The comments in the Main.go file are as follows:

+build Darwin Linux Windows
Here to indicate the different environments that the compilation applies to. Only those that meet the criteria will be compiled, so there are 2 main functions, and the compilation does not conflict.

Reference:

http://blog.csdn.net/varding/article/details/12675971

Http://dave.cheney.net/2013/10/12/how-to-use-conditional-compilation-with-the-go-build-tool

Android App Launch portal

APK file itself is a compressed package, directly with the decompression tool can be opened, but the inside of the files have been encoded into binary file format, not directly see, such as program description file Androidmanifest.xml, using the Apktool tool can be decoded to restore the files.
Apktool (http://code.google.com/p/android-apktool/now address is: http://ibotpeaches.github.io/Apktool/) is a very well-known open source Toolkit, Powerful, can unpack apk files and repackage, commonly used to Chinese Android applications.

Apktool installation method See: http://ibotpeaches.github.io/Apktool/install/

Reference: http://kenkao.iteye.com/blog/1890497

Using this tool we can see the contents of the Androidmanifest.xml file for the basic.apk file as follows:

<?xml version= "1.0" encoding= "Utf-8"?>
<manifest package= "Org.golang.todo.basic" android:versioncode= "1" android:versionname= "1.0"
Xmlns:android= "Http://schemas.android.com/apk/res/android" >
<application android:label= "Basic" android:debuggable= "true" >
<activity android:name= "org.golang.app.GoNativeActivity" android:label= "Basic" android:configchanges= " Keyboardhidden|orientation ">
<meta-data android:name= "Android.app.lib_name" android:value= "Basic"/>
<intent-filter>
<action android:name= "Android.intent.action.MAIN"/>
<category android:name= "Android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>
</manifest>

This is the execution entry for the APK file, not the main function entry for server segment development.

The implicit implementation of this activity is org.golang.app.GoNativeActivity.

Specifically, the logic here is encapsulated in the Golang.org/x/mobile/app code.

The main core code is as follows:

Func Main () {
App. Main (func (a app). APP) {
For e: = Range a.events () {
Switch e: = A.filter (E). (type) {
Case lifecycle. Event:
// ...
Case size. Event:
// ...
Case Paint. Event:
// ...
Case Touch. Event:
// ...
}
}
})
}

Different events then trigger different functions. Complete these functions.

You can literally understand what these events are doing.

Lifecycle. Several events related to the event Activity life cycle;

Size. Event screen size Change related events

Paint. Events on the Event painting screen

Touch. Event Touch screen or left mouse button click and Move Events

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.