16 Knowledge of Android Developer Essentials

Source: Internet
Author: User
<span id="Label3"></p><p>Android Development Novice must, This is what I saw in the wheat college forum, feel very good, share to everyone:<br>1. Activity Life cycle, change of activity state when the screen is Switched.<br>Life Cycle:<br>Complete Life cycle:<br>That is, from an activity to disappear, the corresponding cycle method is: OnCreate to ondestroy;<br>Start:<br>Three methods of OnCreate ()->onstart ()->onresume;<br>Back Key:<br>When we press the back key, we this application will end, this time we will successively call OnPause ()->onstop ()->ondestory () three methods;<br>Home key:<br>OnPause ()->onstop (); The application was not destroyed at this time;<br>Start again: onrestart ()->onstart ()->onresume () three methods<br>Toggle Screen:<br>(1) when the activity android:configchanges is not set:<br>Simulator in this case, the screen will recall the life cycle, cut across the life cycle of the screen will be executed once, cut the vertical screen when the life cycle will be executed two times, and the horizontal screen onconfigurationchanged is not called.<br>But the test results on the phone are: the life cycle is executed only once, and the screen onconfigurationchanged is not called.<br>(2) when setting the Activity's android:configchanges= "orientation":<br>Simulator in this case, the screen will recall the various life cycle, cut horizontal screen onconfigurationchanged not executed, vertical screen when the onconfigurationchanged executed 1 times.<br>however, the test results on the phone are: the life cycle has not changed, and the screen onconfigurationchanged is only performed once.<br>(3) when setting the Activity's android:configchanges= "orientation|keyboardhidden":<br>Simulator in this case, the screen will not recall the life cycle, cut the screen when the onconfigurationchanged will execute 1 times, cut the vertical screen when the Onconfigurationchanged method call 2 Times.<br>But the test results on the phone are: the onconfigurationchanged is executed only once.<br>2, if the background activity for some reason by the system is recycled, how to save the current state before being reclaimed by the system?<br>Onsaveinstancestate ();<br>When an activity a in your program runs, either actively or passively runs another activity B, at which point a executes onsaveinstancestate ().<br>b After the completion of a, this time there are two cases: A is recycled, one is not recycled, then it needs to recall the OnCreate () method, The difference is that the OnCreate () method with parameters, saveinstancestate Instead of being recycled, the Onresume () is executed directly, skipping the OnCreate () method.<br>3, start an application, you can click on the main interface icon to enter, you can also jump from a program to go in, What is the difference between the two?<br>Enter from the main interface:<br>Is the activity of the execution Androidmainfest.xml file, category marked as android.intent.action.MAIN;<br>Belong to an explicit invocation;<br>To jump from another program to Enter:<br>is an implicit call, the Android system chooses which activity to use in response to the Activity's intent-filter;<br>4. What is the storage mode of android? What types of data are used to store them individually?<br>4 Ways to Store:<br>(1) sharedpreference;<br>The INI file, similar to CS development, is used to save some simple properties in the application, located at:<br>/data/data/<packagename>d_prefs_***.xml, we are unable to share this file in multiple apps;<br>(2) file storage;<br>Files are used to store big data, and the Java.io.* library provides I/O interfaces to read and Write. The advantage is that large volumes of data can be stored, with the drawback that file updates or formatting changes can lead to huge programming efforts;<br>(3) SQLite database;<br>SQLite is a lightweight database, and Android encapsulates a sqlitedatabase class that encapsulates some of the APIs that manipulate the database, using the class to perform database operations Instead.<br>(4) ContentProvider<br>Since data in Android is private, ContentProvider is needed if you need to use this data in other Applications.<br>ContentProvider is a bridge between data storage and retrieval across all applications, and his role is to enable data sharing between applications.<br>Android systems have provided ContentProvider (tablets, videos, audio, and Communications) for some of the most common Data.<br>Each contengprovider provides a public uri, and if the application data needs to be shared, it is necessary to use ContentProvider to provide a URI for the data, and the other application can manipulate the data with this Uri.<br>5, Serializable and Parcelable difference.<br>Serializable is a standard Java interface;<br>Parcelable is an android-specific interface that is more efficient than seriallizable.<br>(1) when using memory, parcelable performance is higher than serializable.<br>(2) parcelable cannot be used in situations where the data is to be stored on disk, as he cannot guarantee the continuity of the data in the event of a change in the outside WORLD.<br>(3) seriallizable generates a large number of temporary variables at serialization time, resulting in frequent gc.<br>6. Can asynctask be created in the thread? Asynctask.execute () can be executed multiple times, if not, how to achieve?<br>Not to;<br>Asynctask is characterized by the task running outside the main thread, while the callback method is executed in the main thread, which effectively avoids the hassle of using handler.<br>Can only be performed once;<br>7, suitable for different resolution screen, layout, material considerations?<br>(1) about layout XML files<br>In the Res directory to create a different layout folder, such as layout-640x360,layout-800x480, all layout files will be written to R.java after compilation, and the system will be based on the size of the screen to choose the appropriate layout for Use.<br>(2) about the design of picture resources<br>Res directory, built drawable-mdpi, drawable-ldpi, drawable-hdpi Three directories, these three are mainly to support Multi-resolution. DRAWABLE-HDPI inside storage high-resolution pictures, drawable-mdpi inside storage medium-resolution pictures, drawable-ldpi inside storage of low-resolution images, the system will be based on the resolution of the machine to each of these folders to find the corresponding Picture. In the development of the program in order to be compatible with different platforms different screens, the respective folders according to the needs of different versions of the Picture.<br>Can first help designers for 960x640 resolution of the phone design a set of diagrams, this set of images can be used for iOS 4;<br>Reduce this set of figures by 50%, the resulting graph can be directly to iOS 3 and 480x320 phone;<br>Reduce this set of figures to 80%, the resulting figure can be directly used for 800x480 mobile phone;<br>Then you carefully look at the Zoomed-out figure, if you find that a certain look is really not good, let the designer redesign a, because the figure is reduced, it may be deformed or something.<br>So down, has realized the 960x640, 800X480, 480x320 three kinds of resolution phone;<br>Next...<br>854x480 resolution phone can directly use the 800x480 map, of course, you need to specifically design a few special pictures, such as splash, aboutme and so On.<br>As for the "miss", ignore it.<br>For higher resolution phones, redesign it.<br>In addition, good use of 9.png;<br>The 9.png format picture is a newly created one on the Android platform that is stretched without losing true, and he can guarantee that the image will be stretched without Distortion.<br>Developer.android.com/guide ...<br>(3) about the units in the layout file<br>Try to use dp, dip;<br>8, If there is more than 500Item in a listview, will there be performance problems? How to optimize? What if a network picture is included in each item?<br>ListView optimization:<br>(1) using contentview;<br>(2) using viewholder;<br>(3) image data using asynchronous loading and caching mechanism;<br>9. What do I need to do if the gallery control displays 5 more than 2M of network pictures at the same time?<br>(1) Scaling Dimension loading, decodestream;<br>(2) cache to local, do not download the same image;<br>(3) consider the use of soft reference, load the first load from a soft reference, the soft reference does not, then go to the local read, local no, load from the network, load the time please pay attention to Scaling.<br>10, realize the realization idea of Android Address book backup to Sdcard.<br>The Android system provides contentprovider for the sharing of Address book information, as long as we use this contentprovider to read the address book data and write it to Sdcard.<br>11. What are the adb,ddms, respectively? List several adb commands;<br>ADB is the main debugging tool for android, and Android debugging Beidge,ddms is a graphical tool built on the ADB foundation.<br>ADB install/home/myname/test.apk<br>ADB devices<br>ADB push<br>ADB pull<br>12. Why do I need to sign the Android app when It's published? Describes the signature Principle.<br>Why would you sign it?<br>(1) Developer Identity authentication;<br>Since the developer may be able to replace the installed program with the exact same package name, this will ensure that the app is not replaced;<br>(2) ensure the integrity of information transmission<br>signature, processing each file in the package to ensure that the contents of the package are not Replaced.<br>(3) to prevent the occurrence of repudiation during the transaction, which is the market requirements for the application<br>The principle of signature:<br>?<br>13, How to package non-conventional resources, such as db data files, sound files, font files?<br>You can use Res/raw and assets:<br>(1) the files in both directories will be stored intact in the APK package after packaging, and will not be compiled into binary.<br>(2) the files in the Res/raw are mapped to the R.java file, and the files under the R.id.filename;assets folder are not mapped to R.java when accessed, and Assetmanager classes are required for ACCESS.<br>(3) Res/raw can not have a directory structure, and assets can have a directory structure, that is, assets directory can be re-established folder<br>(4) the files in both directories can not be too large, the official data 1M, if more than 1M can be considered to cut the file, when used in Stitching.<br>14, when using webview, the inside of JS how to call Java function? What's The reverse?<br>JavaScript is called in Java:<br>Mwebview.getsettings (). setjavascriptenabled (true);<br>Mwebview.loadurl ("javascript:test ()");<br>Java is called in Javascript:<br>Mwebview.addjavascriptinterface (obj, "demo");<br>15. How do I safely exit a application that has called multiple activity?<br>For a single activity application, the exit is simple, just finish ().<br>of course, You can also use killprocess () and System.exit () methods.<br>however, for multi-activity applications, The top method is useless if you want to exit the last activity immediately after you open multiple activity, because the top method is to end an Activity.<br>The General Approach:<br>Each activity is opened and Recorded. When you need to exit, close each Activity.<br>1.public class MyApp extends application {private list<activity> mainactivity = new Arraylist<activity> (); Public list<activity> mainactivity () {return mainactivity;} public void addactivity (Activity Act) {mainactivity.add (act);} public void Finishall () {(Activity act:mainActivity.tasks) {if (!act.isfinishing ()) {act.finish ()}} Mainactivity.tasks = null;} @Overridepublic void onCreate () {super.oncreate (); setState (we); MyApp appState = (myapp) getapplicationcontext (); appstate.addactivity (this)}<br>Copy Code<br>1.<br>2.MyApp appState = (MyApp) getapplicationcontext (); appState. finishall ()<br>Copy Code<br>16. There are several methods of registering broadcastreciver.<br>Two KINDS.<br>(1) Registration at Androidmanifest.xml<br>1.<receiver><intent-filter><action android:name= ""/></intent-filter></receiver><br>Copy Code<br><br>This method has a feature that even if your application is closed, the Broadcastreceiver will still accept the broadcast object, which means that the broadcast event can be accepted regardless of whether your application is active or Closed.<br>(2) Registering in the code<br></p><p><p>1.IntentFilter filter=new intentfilter (); filter.addaction ();</p></p><p><p>Transfer from: Wheat Academy (www.maiziedu.com)</p></p><p><p></p></p><p><p>16 Knowledge of Android Developer Essentials</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.