Basic 4 Android Basics

Source: Internet
Author: User
<span id="Label3"></p><p><p><span style="font-size: 16px;">Basic 4 Android Basics</span></p></p><p><p>1. Activity and Fragment Life Cycle.</p></p><p><p></p></p><p><p>Activity life cycle</p></p><p><p>Open App OnCreate ()->onstart ()->onresume</p></p><p><p>Press the back key onPause ()->onstop ()->ondestory ()</p></p><p><p>Press Home key OnPause ()->onstop ()</p></p><p><p>Start Onrestart ()->onstart ()->onresume again ()</p></p><p><p></p></p><p><p></p></p><p><p>The life cycle of fragment</p></p><p><p>Switch to the fragment Onattach () onCreate () oncreateview () onactivitycreated () onStart () onresume ()</p></p><p><p>Screen off OnPause () onsaveinstancestate () onStop ()</p></p><p><p>Screen unlock OnStart () onresume ()</p></p><p><p>Switch to other fragment onPause () onStop () ondestroyview ()</p></p><p><p>Switch back to itself fragment Oncreateview () onactivitycreated () onStart () onresume ()</p></p><p><p>Back to Desktop OnPause () onsaveinstancestate () onStop ()</p></p><p><p>Back to Application OnStart () Onresume ()</p></p><p><p>Exit application OnPause () onStop () ondestroyview () ondestroy () Ondetach ()</p></p><p><p></p></p><p><p>2. Acitivty's four-medium start mode and Features.</p></p><p><p>When the application is running, a thread is opened and a task stack is run on the thread, which is put into the task stack when the activity instance is Created. The activity startup mode is set in the Androidmanifest.xml file by configuring the Activity's properties android:launchmode= "" setting</p></p><p><p>Standard mode (default) as soon as you create an activity instance, once the activity is activated, a newly created instance is added to the task stack, and exiting the activity destroys the instance in the task stack</p></p><p><p>The Singletop mode considers whether the activity instance currently being activated is at the top of the stack in the task stack, and if it is at the top of the stack without recreating the new instance, the existing instance will be reused or a new instance will be created in the task stack</p></p><p><p>Singletask mode If there is an activity instance of the pattern in the task stack, the activity instance above that instance in the stack is removed, and the activity is reused by invoking the Newinstance () method of the instance, so that the instance is in the top position of the STACK. otherwise, Re-create a new activity instance</p></p><p><p>SingleInstance mode When the activity instance is created in the task stack, the activity is reused by invoking the Newinstance () method of the instance as long as the instance is still in the task stack, that is, as long as the activity of that type is Activated.</p></p><p><p>The same activity instance is used at this point, and it will be at the top of the stack of the task Stack. This mode is typically used to load slower, less expensive activity that does not need to be recreated every Time.</p></p><p><p></p></p><p><p>3. Activity Caching Method.</p></p><p><p>Onsaveinstancestate () and Onrestoreinstancestate () are not part of the activity lifecycle and are called only if an activity is accidentally destroyed.</p></p><p><p>If there is not enough memory, the home key is pressed (note: pressing the back key is an active destruction of an activity, and these two methods will not be called). You can also use these two methods to stage some data when you need to change the orientation of the Screen.</p></p><p><p>The following example of Baidu map application, The use of these two methods, used to save and restore the map VIEW.</p></p><pre><span style="color: #000000;"><span style="color: #000000;">@Override</span></span><span style="color: #0000ff;"><span style="color: #0000ff;">protected</span></span> <span style="color: #0000ff;"><span style="color: #0000ff;">void</span></span><span style="color: #000000;"><span style="color: #000000;">onsaveinstancestate (Bundle Outstate) {cPoint</span></span>= Mapview.getmapcenter ();<span style="color: #008000;"><span style="color: #008000;">//</span></span><span style="color: #008000;"><span style="color: #008000;">gets the center point of the current MAPVIEW. </span></span>Outstate.putint ("lat", Cpoint.getlatitudee6 ());<span style="color: #008000;"><span style="color: #008000;">//</span></span><span style="color: #008000;"><span style="color: #008000;">temporary presence in outstate</span></span>Outstate.putint ("lon"<span style="color: #000000;"><span style="color: #000000;">, Cpoint.getlongitudee6 ()); </span></span><span style="color: #0000ff;"><span style="color: #0000ff;">Super</span></span><span style="color: #000000;"><span style="color: #000000;">. Onsaveinstancestate (outstate);} @Override</span></span><span style="color: #0000ff;"><span style="color: #0000ff;">protected</span></span> <span style="color: #0000ff;"><span style="color: #0000ff;">void</span></span><span style="color: #000000;"><span style="color: #000000;">onrestoreinstancestate (Bundle Savedinstancestate) {</span></span><span style="color: #0000ff;"><span style="color: #0000ff;">int</span></span>Lat = Savedinstancestate.getint ("lat");<span style="color: #008000;"><span style="color: #008000;">//</span></span><span style="color: #008000;"><span style="color: #008000;">recovering from saved data</span></span> <span style="color: #0000ff;"><span style="color: #0000ff;">int</span></span>Lon = Savedinstancestate.getint ("lon"<span style="color: #000000;"><span style="color: #000000;">); CPoint</span></span>=<span style="color: #0000ff;"><span style="color: #0000ff;">New</span></span><span style="color: #000000;"><span style="color: #000000;">GeoPoint (lat, lon);</span></span><span style="color: #0000ff;"><span style="color: #0000ff;">Super</span></span><span style="color: #000000;"><span style="color: #000000;">. Onrestoreinstancestate (savedinstancestate);}</span></span></pre><p><p></p></p><p><p>4. Service Life cycle, Two startup methods, what is the Difference.</p></p><p><p>StartService Visitor Exit Service still allows onCreate Onstartcommand OnDestroy</p></p><p><p>Bindservice Visitor exits service termination oncreate onbind Onunbind OnDestroy</p></p><p><p></p></p><p><p>5. How to ensure that the service is not Killed.</p></p><p><p>1 Onstartcommand method, return start_sticky</p></p><p><p>2 Increase Service Priority android:priority = "1000"</p></p><p><p>3 Improve service Process priority</p></p><p><p>4 Restart Service in OnDestroy method</p></p><p><p></p></p><p><p>6. What is the difference between the two methods of registration for broadcasting?</p></p><p><p>1. Register in the Androidmanifest.xml file.</p></p><p><p>Benefit: once the application is installed on the phone, broadcast receiver will start to take Effect. A broadcast event can be accepted regardless of whether the application process is running or not and whether the program is open</p></p><p><p><receiver android:name= ". Receiver. Smsreceiver "></p></p><p><p><intent-filter android:priority= ">"</p></p><p><p><action android:name= "android.provider.Telephony.SMS_RECEIVED"/></p></p><p><p></intent-filter> </receiver></p></p><p><p>2. Registering broadcast benefits by code: once the application is stopped, the broadcast stops.</p></p><p><p>Intentfilter filter = new Intentfilter (intent.action_screen_off);</p></p><p><p>Filter.setpriority (1000);</p></p><p><p>Lockscreenreceiver myreceiver = new Lockscreenreceiver ();</p></p><p><p>Registerreceiver (myreceiver, filter);</p></p><p><p></p></p><p><p>7. How to use intent, which data types can be Passed.</p></p><p><p>PutExtra ()</p></p><p><p>Basic data Type Boolean byte char short int long float double</p></p><p><p>String charsequence parcelable Serializable Bundle Array Collection</p></p><p><p></p></p><p><p>8. How to use Contentprovider.</p></p><p><p>Change and delete</p></p><pre>Contentresolver resolver =<span style="color: #000000;"><span style="color: #000000;">Getcontentresolver (); URI</span> uri</span>= Uri.parse ("content://media/internal/images"<span style="color: #000000;"><span style="color: #000000;">);</span></span><span style="color: #008000;"><span style="color: #008000;">//</span></span><span style="color: #008000;"><span style="color: #008000;">Add a record</span></span>Contentvalues values =<span style="color: #0000ff;"><span style="color: #0000ff;">New</span></span><span style="color: #000000;"><span style="color: #000000;">contentvalues (); values.put (</span></span>"name", "linjiqin"<span style="color: #000000;"><span style="color: #000000;">); Values.put (</span></span>"age", 25<span style="color: #000000;"><span style="color: #000000;">); Resolver.insert (uri, values); </span></span><span style="color: #008000;"><span style="color: #008000;">//</span></span><span style="color: #008000;"><span style="color: #008000;">get all records in the person table</span></span>cursor cursor = Resolver.query (uri,<span style="color: #0000ff;"><span style="color: #0000ff;">NULL</span></span>,<span style="color: #0000ff;"><span style="color: #0000ff;">NULL</span></span>,<span style="color: #0000ff;"><span style="color: #0000ff;">NULL</span></span>,<span style="color: #0000ff;"><span style="color: #0000ff;">NULL</span></span><span style="color: #000000;"><span style="color: #000000;">);</span></span><span style="color: #0000ff;"><span style="color: #0000ff;"></span> while</span><span style="color: #000000;"><span style="color: #000000;">(cursor.movetonext ()) {}</span></span><span style="color: #008000;"><span style="color: #008000;">//</span></span><span style="color: #008000;"><span style="color: #008000;">Change the Name field value of the record with ID 1 to the new Zhangsan</span></span>Contentvalues updatevalues =<span style="color: #0000ff;"><span style="color: #0000ff;">New</span></span><span style="color: #000000;"><span style="color: #000000;">contentvalues (); updatevalues.put (</span></span>"name", "zhangsan"<span style="color: #000000;"><span style="color: #000000;">); Uri Updateiduri</span></span>= Contenturis.withappendedid (uri, 2<span style="color: #000000;"><span style="color: #000000;">); resolver.update (updateiduri, updatevalues,</span></span><span style="color: #0000ff;"><span style="color: #0000ff;">NULL</span></span>,<span style="color: #0000ff;"><span style="color: #0000ff;">NULL</span></span><span style="color: #000000;"><span style="color: #000000;">);</span></span><span style="color: #008000;"><span style="color: #008000;">//</span></span><span style="color: #008000;"><span style="color: #008000;">Delete a record with an ID of 2</span></span>Uri Deleteiduri = Contenturis.withappendedid (uri, 2<span style="color: #000000;"><span style="color: #000000;">); resolver.delete (deleteiduri,</span></span><span style="color: #0000ff;"><span style="color: #0000ff;">NULL</span></span>,<span style="color: #0000ff;"><span style="color: #0000ff;">NULL</span></span>);</pre><p><p></p></p><p><p>9. Thread, asyctask, Intentservice use scenes and Features.</p></p><p><p></p></p><p><p>10. Five kinds of layouts: framelayout, linearlayout, absolutelayout, relativelayout, tablelayout respectively, and comparison of drawing Efficiency.</p></p><p><p></p></p><p><p>A. Android data storage format.</p></p><p><p></p></p><p><p>Basic operation of Sqlite.</p></p><p><p></p></p><p><p>The MVC pattern in Android.</p></p><p><p></p></p><p><p>The role of Merge and viewstub.</p></p><p><p></p></p><p><p>What are the advantages and disadvantages of json?</p></p><p><p></p></p><p><p>16. What are the two types of animations, and what are the characteristics of each?</p></p><p><p></p></p><p><p>Handler, Loop Message Queuing model, The role of each part.</p></p><p><p></p></p><p><p>18. How to opt out of terminating the app.</p></p><p><p></p></p><p><p>The difference between The. Asset directory and the Res directory.</p></p><p><p></p></p><p><p>How Android speeds up Activity.</p></p><p><p></p></p><p><p>Android Memory Optimization method: ListView optimization, timely shutdown of resources, picture cache and so On.</p></p><p><p></p></p><p><p>Application scenarios for weak references and soft references in ANDROID.</p></p><p><p></p></p><p><p>The four attributes of bitmap, and the size of each of the attribute Formations.</p></p><p><p></p></p><p><p>View and view Group Categories. Custom View procedure: onmeasure (), onlayout (), onDraw ().</p></p><p><p></p></p><p><p>Touch Event Distribution Mechanism.</p></p><p><p></p></p><p><p>Android long connection, How to deal with the heartbeat Mechanism.</p></p><p><p></p></p><p><p>The start-up process of Zygote.</p></p><p><p></p></p><p><p>The Android ipc:binder principle.</p></p><p><p></p></p><p><p>29. What frame have you used, whether you have read the source code, whether you know the underlying principle.</p></p><p><p></p></p><p><p>Android5.0, 6.0 New Features.</p></p><p><p></p></p><p><p>Android words, Many are some of the practice of the project, the use of more, naturally know, there is a lot of celebrities to visit the blog, the book can talk about not many things. In addition to the bottom of the Android thing, there is time to learn more about, add Sub-items.</p></p><p><p></p></p><p><p>Recommended Books: "crazy Android handout" "deep Understanding android"</p></p><p><p></p></p><p><p>Basic 4 Android Basics</p></p></span>

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.