Basic knowledge of Android

Source: Internet
Author: User
1. Activity lifecycle. The Activity status changes during screen switching.Life cycle: Completed life cycle: that is, from an Activity to disappear, the corresponding cycle method is: onCreate to onDestroy; Start: onCreate ()-> onStart () -> onResume three methods; BACK key: When we press BACK, our application will end. At this time, we will call onPause ()-> onStop () successively () -> onDestory () three methods; HOME Key: onPause ()-> onStop (); at this time, the application is not destroyed; restart: onRestart ()-> onStart () -> onResume (): (1) when the android: configChanges of the Activity is not set: In this case, the simulator re-calls the life cycle of the Activity, the Live Cycle of the landscape screen is executed once, the Live Cycle is executed twice when the landscape screen is switched, and the onConfigurationChanged function is not called. However, the test result on the mobile phone is: the life cycle is only executed once, And the onConfigurationChanged screen is not called. (2) When setting Activity android: configChanges = "orientation": In this case, the simulator will still re-call each lifecycle when switching the screen, the onConfigurationChanged command is executed once when the onConfigurationChanged command is not executed or the landscape is portrait. However, the test result on the mobile phone is: the life cycle has not changed, and the onConfigurationChanged operation is only executed once. (3) When setting Activity android: configChanges = "orientation | keyboardHidden": In this case, the live cycle is not re-called by the simulator. onConfigurationChanged will be executed once when the landscape is switched, the onConfigurationChanged method is called twice when the portrait screen is switched. However, the test result on the mobile phone is: The onConfigurationChanged screen is executed only once. 2. If the background Activity is recycled by the system for some reason, How can I save the current status before being recycled by the system?OnSaveInstanceState (); when one Activity A in your program is running, it actively or passively runs another Activity B. At this time, A will execute onSaveInstanceState (). B comes to A again. There are two situations at this time: A is recycled, and A is not recycled. If it is recycled, The onCreate () method needs to be called again, the difference is that the onCreate () method carries the parameter 'saveinstancestate'. If it is not recycled, The onResume () method is directly executed and the onCreate () method is skipped. 3. Start an application. You can click the icon on the main interface or jump in from a program. What is the difference between the two?Enter from the main interface: Execute androidMainfest. in the xml file, category is marked as android. intent. action. activity of MAIN; it is an explicit call; jump from other programs to: it is an implicit call. The Android system selects the Activity to be used for response based on the Intent-Filter of the Activity; 4. What storage methods does Android provide? What types of data do they apply?Four storage methods: (1) SharedPreference. Similar to the INI file in CS development, it is used to save some simple properties in the application: /data/<packagename>/shared_prefs _***. xml, we cannot share this file in multiple Apps; (2) file storage; files are used to store big data, using java. io. * The database provides I/O interfaces for reading and writing. The advantage is that it can store large data volumes. The disadvantage is that file updates or format changes may lead to huge programming work. (3) SQLite database; SQLite is a lightweight database, android encapsulates a SQLiteDatabase class, which encapsulates APIs for database operations. You can use this class to perform database operations. (4) ContentProvider because the data in Android is private, if you need to use the data in other applications, you need to use ContentProvider. ContentProvider is a bridge between data storage and retrieval among all applications. Its role is to share data among various applications. The Android system has provided ContentProvider (slice, video, audio, and address book) for some common data. Each ContengProvider provides a public URI. If application data needs to be shared, you need to use ContentProvider to provide a URI for the data, and other applications can perform operations on the data. 5. Differences between Serializable and Parcelable.Serializable is a standard Java interface; Parcelable is a unique Android interface, which is more efficient than Seriallizable. (1) When using memory, Parcelable performance is higher than Serializable. (2) Parcelable cannot be used to store data on a disk, because it cannot guarantee data continuity in the case of external changes. (3) Seriallizable will generate a large number of temporary variables during serialization, resulting in frequent GC. 6. Can asynctask be created in a thread? Can asynctask.exe cute () be executed multiple times? If not, how can this problem be implemented?No; AsyncTask is characterized by running tasks outside the main thread, and the callback method is executed in the main thread, which effectively avoids the trouble of using Handler. It can be executed only once; 7. What are precautions for layout and materials when the screen is adapted to different resolutions?(1) create different layout folders in the res directory for layout XML files, such as layout-640 × 360, layout-800 × 480, all layout files are written to R. java, and the system selects the appropriate layout based on the screen size. (2) In the res directory of image resource design, three directories, drawable-mdpi, drawable-ldpi, and drawable-hdpi, are created to support multi-resolution. Drawable-hdpi stores high-resolution images, drawable-mdpi stores medium-resolution images, and drawable-ldpi stores low-resolution images, the system will find the corresponding images in these folders according to the machine resolution. To be compatible with different screens on different platforms, different versions of images are stored in different folders as needed. You can help the designer design a set of pictures for the 960X640 resolution mobile phone. This set of pictures can be used for IOS 4, and this set of pictures can be reduced by 50%, the obtained figure can be used for IOS 3 and 480X320 mobile phones. The figure is reduced to 80% and can be used for 800x133 mobile phones; then, you can carefully observe the reduced image. If you find that a certain image looks really bad, you can ask the designer to design a new one, because it may be distorted .. In this way, we have achieved 960X640, 800X480, and x320 resolution mobile phones. Next... X resolution mobile phones can use a x image directly. Of course, you need to design several special images, such as splash and aboutMe .. For 320X240, ignore it .. For mobile phones with higher resolution, design them again .. In addition, the 9.png00009.png format is a new feature created on the Android platform that is stretched but not distorted. Developer.android.com/guide... (3) Use dp and dip as much as possible in layout files; 8. If a listview contains more than 500 items, will there be performance problems? How to optimize it? What if each item contains a network image?ListView optimization: (1) Using contentView; (2) using viewHolder; (3) using asynchronous loading and caching of image data; 9. What do I need to do if the gallery control displays 5 network images larger than 2 MB at the same time?(1) Resize and load, decodeStream; (2) cache to local, without downloading the same image; (3) Consider using soft references, first load from soft references, if there is no soft reference, it will be read locally. If there is no local reference, it will be loaded from the network. Pay attention to scaling during loading. 10. How to back up the android address book to sdcard.The Android system provides the ContentProvider for Address Book information sharing. You only need to use this ContentProvider to read the address book data and write it to SDCard. 11. What are ADB and ddms doing? List several ADB commands;Adb is the main debugging tool for Android, Android debugging beidge, and ddms is a graphical Tool Based on adb. Adb install/home/myname/test.apk adb devicesadb pushadb pull 12. Why should I sign the Android app when it is released? Briefly describe the signature principles.Why signature? (1) Developer identity authentication; because developers may open the same Package Name to replace the installed program, this ensures that the App is not replaced; (2) ensure the integrity signature of information transmission, and process each file in the package to ensure that the content in the package is not replaced. (3) prevent Denial of Service in the transaction process. This is the principle that Market requires to sign the application :? 13. How do I package unconventional resources, such as DB data files, sound files, and font files?You can use res/raw and assets: (1) files in the two directories will be stored in the apk package intact after being packaged, and will not be compiled into binary. (2) files in res/raw will be mapped to R. in the java file, the resource ID is R. id. filename; files in the assets folder will not be mapped to R. in java, the AssetManager class is required for access. (3) res/raw cannot have a directory structure, while assets can have a directory structure, that is, folders can be created under the assets Directory (4) the files in these two directories cannot be too large, and the official data is 1 MB. If the size exceeds 1 MB, you can consider cutting the files and splicing them during use. 14. How can Js in webview call Java functions? What about the opposite?Java calls Javascript:
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.