"Ios-android development control" app Portal

Source: Internet
Author: User

"Ios-android development control" app Portal

[Picture Android vs IOS]

Outline

    1. The entrance to the ios,android was analyzed,

    2. Ios,android Interface Unit

    3. Why do we have that life cycle?

    4. How to write inheritance and abstract classes, such as Factory mode

    5. The strength of the object. Features of iOS

Program entry (Entry point)



#首先来看iOS应用的入口:

int main(intchar * argv[]){    @autoreleasepool {        returnclass]));    } }

The same as all C programs. The main function is the entrance to the OBJECTIVE-C program.

Although this main method returns an int, it does not actually return. It will persist in memory until the user or system forces it to terminate.

Above UIApplicationMain it comes from UIKit , is a very important function.

Say the number of participants, the first two participants all understand.

The third parameter is a uiapplication class name or its subclass name. Assuming nil, the UIApplication class name is used by default.

The fourth parameter is the Appdelegate class as the application's entrusted object, used to monitor the application life cycle related to the Trust method.

The UIApplication central role of this is to provide control and collaboration during the execution of the iOS program.

It creates several core objects of the app, such as: Uiapplicationdelegate UIWindow, UIView, to handle the process:

    1. The program entry main function creates the UIApplication instance and the UIApplication proxy instance.

    2. Loading the user interface from available storyboard files

    3. Call Appdelegate yourself to define the code to do some initialization settings

    4. Put the app in the main Run loop environment to respond to and handle events generated by user interaction

This UIApplication object is set at startup and Main Run Loop uses it to handle events and update the view-based interface, where main Run loop is the main thread of the application.

[Image IOS, Swift, Android tag]



Talk about Swift's entrance:

In the swift language, the compiler will no longer look for the main function as the entry for the program, but rather a main.swift file.
The first line of code in the file defaults to the entry of the program, and can be added to the code such as the following:

UIApplicationMain(C_ARGC, C_ARGV, nil,     NSStringFromClass(AppDelegate))

Yes, that's what we mentioned earlier UIApplicationMain .

Here C_ARGC, the C_ARGV global variable is the one in the main function.
ARGC, argv.

In addition, you can add tags to the swift file to indicate the entry of the @UIApplicationMain project. Doing so causes the compiler to ignore the Main.swift portal file. The file labeled @uiapplicationmain is used as a portal file.



#再来看看Android的:

Android Program you can't find an explicit main method

Although Java also has the main method, Android seems to be unable to find the main.

For this problem. There are very many explanations.

StackOverflow explained that there is no main because it does not need main, the system generates activity and calls its methods, the application default boot has replaced main, so there is no need to use the main method.

So where is the entrance to the program? We look at it from the Application beginning.

Every Android app in the package. Has a manifest file that declares its components. We can see for example the following code:

<manifest  ...    <application  ...        <activity android:name=".MainActivity" android:label="@string/app_name">             <intent-filter>                 <action android:name="android.intent.action.MAIN" />                 <category android:name="android.intent.category.LAUNCHER" />             </intent-filter>         </activity>     </application></manifest>

In this XML-written manifest file, the <application/> label is on the outermost layer.

Among them, this marked the Android.intent.category.LAUNCHER <activity/> is the program start the default interface.

But they are not the real entrances.

The real portal for Android apps is the ActivityThread.main method

This is an implicit entry, and the code has made certain simplifications such as the following:

public  static  void  main  (string[] args) { Some test defaults ...  Looper.preparemainlooper (); //create message loop looper  Activitythread thread = new  activitythread (); Thread.attach (false ); if  (Smainthreadhandler = = null ) {Smainthreadhandler = Thread.gethandler (); //UI thread Handler } Asynctask.init (); Looper.loop (); //execution message loop  throw  new  RuntimeException ( "Main thread loop unexpectedly exited" ); } 

#深入一下:

Inheritance Relationship:

java.lang.Object   ?    android.content.Context       ?    android.content.ContextWrapper           ?    android.app.Application

The bottom of Android is Linux Kernel , iOS is XNU Kernel , what's the difference between them?

Activity and Uiviewcontroller

Android activity and fragment are the main interface components, while iOS is Uiviewcontroller. Almost all of the view and space will be placed in activity and Uiviewcontroller.

There are a number of extensions on top:

Android:Fragmentactivity, appcompatactivity

IOS:Uitableviewcontroller, Uicollectionviewcontroller

Let's compare the inheritance relationship:

Android:Activity->ContextThemeWrapper->ContextWrapper->Context

IOS:UIViewController->UIResponder->NSObject

iOS almost all of the base classes are nsobject,android and have an object, which is generally used as the base class for the model layer object.

Life cycle

There is a lot of information on this, and I would simply say:

Android activity, onCreate() in the initialization of operations, onResume() can add some changes in the interface and state of operation;

iOS Uiviewcontroller, -viewDidLoad in the initialization operation, -viewWillAppear can add some changes in the interface and state operation;

Compare:

Activity:OnCreate () –> OnStart () –> onresume () –> 执行态 –> onPause () –> onStop () –> OnDestroy ()

UIViewController:-viewdidload–>-viewwillappear–>-viewdidappear–> 执行态 –>-viewwilldisappear–>-viewDidDisappear

Here to add an Android

Fragment:* *onattach () –> onCreate () –> oncreateview () –> onactivitycreate () –> OnStart () –> onresume () –> 执行态 –> onPause () –> onStop () –> ondestroyview () –> OnDestroy () –> ondetach ()

Both Android and iOS use the data structure of the stack to store activity and Uiviewcontroller.

AndroidAbout the activity stack, the ability to search taskAffinity and launchMode . All activity in the same application has the same affinity (taskaffinity), which can be set by Itent flag. can also be set in Androidmanifest.

IOSThe Uinavigationcontroller in the stack to Uiviewcontroller.

Interface jump and pass value

Android:Activity is able to use bundles with intent,fragment. For interface callback values. Received via Startactivityforresult () Start and Onactivityresult ().

IOS:When initializing a Uiviewcontroller object, assign a value directly to the variable in the object. For interface callback values, you can define your own interface (Delegate), and you can also use notifications (Notification)

struct Type class Code
//AndroidClass A extends B implements C
//IOSA.h@interface A : B A.m@implementation A <C>

Strong references and weak references

Android:

There are four kinds of reference types, strong references (strongreference), soft references (softreference), weak references (weakreference), virtual references (Phantom Reference).
Objects that are typically created are strong references. So when there is not enough memory space, the Java virtual Machine prefers to throw an oom exception. Strongly referenced objects are not recycled.
For soft references. Enough memory space, the garbage collector will not recycle it, can do the image cache.

For weak applications, use scenarios such as: When using handler in Activity, it is necessary to define it as a static internal class form, which allows it to decouple from the external class (Activity) and no longer hold references to external classes. At the same time, because of the handler in the Handlermessage general will have to visit or change the properties of the activity. At this time It is necessary to define a weakreference within the handler that points to this activity so that it does not affect the activity's memory collection at the same time and is able to access the activity's properties under normal circumstances.

Ios:

With __weak, __strong is used to modify variables, declaring an object __strong by default.
In the case of a strong reference, a circular reference can sometimes occur, and a weak reference is required to help (__weak).
A strong reference holds an object, and a weak reference does not hold an object.


Strong references can release objects, but weak references are not sufficient. Because a weak reference does not hold an object, when a weak reference points to an object held by a strong reference, when the strong reference releases the object, the weak reference will voluntarily be assigned nil, that is, the weak reference will voluntarily point to nil.

Private and public

There are methods in iOS -``+ . -equivalent to the private in Android,
+Equivalent to public static in Android.

For global variables, iOS is placed in appdelegate or in. h using the # define declaration.


Android is the same, put in application or use public static in the class.


Of course. are able to use singleton classes.

Basic controls

Against some of the frequently used

Android IOS
TextView UILabel
TextEdit Uitextfield Uitextview
ImageView Uiimageview
Button UIButton
Switch Uiswitch
Listview TableView
Gridview CollectionView

Compare Inheritance:
Android views--View
IOS views, UIView, Uiresponder-NSObject

Java in fact no matter what objects are directly or indirectly inherited from object, write extends object and do not write extends is equivalent.


So Android and iOS objects are essentially inherited from the top-level object.

amazing~

About the stack principle of inheritance and abstract class app startup How to write the startup program entry for the Factory mode app

The article and the Code, also need to continue to comb, constantly iterative.

References

Ios

http://www.jianshu.com/p/aa50e5350852

Http://www.cnblogs.com/ydhliphonedev/archive/2012/07/30/2615801.html

http://swifter.tips/uiapplicationmain/

http://blog.ibireme.com/2015/05/18/runloop/

http://swifter.tips/uiapplicationmain/

Android

Http://www.cnblogs.com/lwbqqyumidi/p/4151833.html

Https://sites.google.com/site/terrylai14/home/android-context-yuan-li

http://blog.csdn.net/chenzheng_java/article/details/6215986

http://blog.csdn.net/chenzheng_java/article/details/6216621

http://blog.csdn.net/bboyfeiyu/article/details/38555547

Other

Android Program Entrance Application onCreate () What has been done, here is a crooked nut print out the onCreate after the stack display log:

Mainactivity.oncreate (Bundle) Line: AInstrumentation.callactivityoncreate (Activity, Bundle) Line:1047Activitythread.performlaunchactivity (Activitythread$activityrecord, Intent) Line:2627Activitythread.handlelaunchactivity (Activitythread$activityrecord, Intent) Line:2679activitythread.access$2300(Activitythread, Activitythread$activityrecord, Intent) Line: theActivitythread$h.handlemessage (Message) Line:2033Activitythread$h (Handler). DispatchMessage (Message) Line: AboutLooper.loop () Line:123Activitythread.main (string[]) Line:4627Method.invokenative (Object, object[], class, class[], class, int, Boolean) Line: notAvailable [native Method] Method.invoke (object, Object ...) Line:521Zygoteinit$methodandargscaller.run () Line:868Zygoteinit.main (string[]) Line:626Nativestart.main (string[]) Line: notAvailable [native Method]

"Ios-android development control" app Portal

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.