<span id="Label3"></p> <p><p>Android and iOS have countless fans as the two most popular mobile operating systems in the world today.</p></p><p><p>So what do the two systems have in common or different for Android or iOS developers? Now let's take a look at the similarities and differences between Android and Ios.</p></p><p><p>Android<br>In Android only the entire interface is present in the Activity. This means that only the user can see is in the Activity. Activity creates a form (window) that we can display using the <code>setContentView()</code> view (UI) that will need to be rendered into the WINDOW.</p></p><p><p><br>Let's take a look at Google's definition of activity:<br>Activity as the user actually sees the Interface. It has its own life cycle, as Google describes it, when an activity is about to Occur. The program first enters the OnCreate method, in which you define some view controls that we need to initialize.<br>Here's a description of Google's activity life cycle:<br></p></p><p><p>`</p></p><pre class="prettyprint"><code class=" hljs cs">``<span class="hljs-keyword"><span class="hljs-keyword">protected</span></span> <span class="hljs-keyword"><span class="hljs-keyword">void</span></span> <span class="hljs-title"><span class="hljs-title">onCreate</span></span>(Bundle Savedinstancestate) The first method that is called when an Activity instance is Started.<p><p></p></p><p><p>Under normal Circumstances. We all cover this method as an entry point for the application, where we do some initialization data, set up the user interface, and so On. In most cases, we're going to load a well-designed user interface from XML here. For example: <span class="hljs-title">Setcontentview</span>(r.layout.main), of Course. You can also read the data that we saved to the storage device from the Savedinstancestate. however, it is necessary to infer whether Savedinstancestate is <span class="hljs-keyword">null</span>, because no data is stored in the device for the first time the Activity is started: <span class="hljs-keyword">if</span>(savedinstancestate!=<span class="hljs-keyword">null </span>) {savedinstancestate. <span class="hljs-keyword"> Get</span>(<span class="hljs-string">"Key"</span>); } <span class="hljs-keyword">protected</span> <span class="hljs-keyword">void</span> <span class="hljs-title">OnStart</span>() The method is called after the <span class="hljs-title">onCreate</span>() method, or when Activity transitions from the Stop state to active State is Called. <span class="hljs-keyword">protected</span> <span class="hljs-keyword">void</span> <span class="hljs-title">Onresume</span> () is called when the Activity transitions from the Pause state to the active State.</p></p><p><p> <span class="hljs-keyword">protected</span> <span class="hljs-keyword">void</span> <span class="hljs-title">Onresume</span> () is called when the Activity transitions from the active state to the Pause State.</p></p><p><p> <span class="hljs-keyword">protected</span> <span class="hljs-keyword">void</span> <span class="hljs-title">OnStop</span> () is called when the Activity transitions from the active state to the Stop State. In general, we save the status information of the Activity Here.</p></p><p><p> <span class="hljs-keyword">protected</span> <span class="hljs-keyword">void</span> <span class="hljs-title">OnDestroy</span> () called when Active is Ended. It is the last method to be called at the end, where it is generally done to release Resources. Clean up memory and so On.</p></p></code><p><p><code class=" hljs cs"></code></p></p></pre><p><p>In android, Activity has four basic statuses:</p></p><pre><pre><code>Active/Runing一个新 Activity 启动入栈后,它在屏幕最前端,处于栈的最顶端,此时它处于可见并可和用户交互的激活状态。Paused 当 Activity 被还有一个透明或者 Dialog 样式的 Activity 覆盖时的状态。<p></p><p>此时它依旧与窗体管理器保持连接,系统继续维护其内部状态,所以它仍然可见。但它已经失去了焦点故不可与用户交互。Stoped 当 Activity 被另外一个 Activity 覆盖、失去焦点并不可见时处于 Stoped状态。</p><p>Killed Activity 被系统杀死回收或者没有被启动时处于 Killed状态。</p></code><p><code></code></p></pre></pre><p><p>When an activity instance is created, destroyed, or initiated by another activity, it transitions between these four states, and the conversion takes place depending on the action of the user Program. Describes the timing and conditions of Activity transitions between different states:<br></p></p><p><p>Ios:<br>In ios, when the app is on, iOS creates a form for it (uiwindow), which is the carrier for your App's display interface, and an iOS app has only one UIWindow Object.</p></p><p><p><br>The real interaction with the user within the UIWindow is the Uiviewcontroller (view controller)<em>PS: at the beginning, I also very do not understand why there is a view controller such things, iOS is the MVC design pattern, And MVC is about the separation between the view and the controller, do not know whether Apple packaged these two things together in the end is good or bad. </em>we display the interface by inheriting Uiviewcontroller (android needs to integrate activity). Uiviewcontroller as the manager of the display Interface. It coordinates its with model objects and other controller objects, including other view Controllers. So all of our interface jumps are done through it (unlike Android using intent). It provides a single, consistent user interface for your Application.<br>Take a look at how the apples define Uiviewcontroller:<br><br>iOS differs from Android in that it requires XML to define the VIEW. There are three ways to display the interface in iOS<br>1. Using code<br>2. Use NIB<br>3. Using Storyboard (essentially Nib)<br>Let's take a look at the flowchart loaded from a view found on the web:<br><br>View refers to the Controller's VIEW.</p></p><p><p>It acts as an attribute of the controler, and the life cycle is within the Controller's life Cycle. This means that your controller cannot be released before the view is Released.<br>When you alloc and init a viewcontroller, the Viewcontroller should not have created a view.</p></p><p><p>Viewcontroller view is created using the Lazyinit (lazy Loading) method. That means you call the View property of Getter:[self view]. The getter will first infer if the view is created, assuming it is not created, then call Loadview to create the VIEW. Loadview will continue to call Viewdidload when Finished. One difference between Loadview and viewdidload is that there is no view at LOADVIEW. And the viewdidload when the view and created Well.<br>OK, take a look at the Uiviewcontroller uninstall:<br><br>When the app receives a memory warning. The Didrecievememorywarning method for each uiviewcontroller is Called. We need to respond by releasing resources that are not needed in the PROCESS. This method is usually Overridden. You need to call the Super method when Overriding.</p></p><p><p>Assuming that the current Uiviewconroller view can be safely released, the Viewwillunload method is called, which we must pay attention to. As the Vc's view disappears when its subviews may be released together, we need to make some records based on the details to ensure that the next time it is created Correctly. There is no memory leak at the same time. After calling Viewwillunload. The Self (uiviewconroller). View property is set to Nil. then, when calling the Viewdidunload method, we are able to release those strongly referenced objects at this Time.</p></p><p><p><br>Anyway<br>When a view controller is Created. and displayed on the Screen.</p></p><p><p>The order in which the code runs</p></p><pre class="prettyprint"><pre class="prettyprint"><code class=" hljs ">1、 alloc 创建对象,分配空间2、init 初始化对象。初始化数据3、loadView 从nib加载视图 ,通常这一步不须要去干涉。</code><p><code class=" hljs "></code></p><p><code class=" hljs ">除非你没有使用xib文件创建视图4、viewDidLoad 加载完毕,能够进行自己定义数据以及动态创建其它控件5、viewWillAppear 视图将出如今屏幕之前。立即这个视图就会被展如今屏幕上了6、viewDidAppear 视图已在屏幕上渲染完毕</code></p></pre></pre><p><p>The order in which a view is removed from the screen and Destroyed. This order is almost identical to the opposite of the Above.</p></p><pre class="prettyprint"><pre class="prettyprint"><code class=" hljs ">1、viewWillDisappear 视图将被从屏幕上移除之前运行2、viewDidDisappear 视图已经被从屏幕上移除。用户看不到这个视图了3、dealloc 视图被销毁,此处须要对你在init和viewDidLoad中创建的对象进行释放</code></pre></pre><p><p>Life cycle switching on the official web:<br></p></p> <p><p>Android vs. iOS comparison (1)------display</p></p></span>
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