Android development FAQ summary

This paper summarizes and analyzes the common problems in Android development. Share with you for your reference, as follows:

1. After using the Scrollview in the UI, if the onkeydown or onkeyup events of the activity are copied, if the focus is on the Scrollview, the two events will not be triggered, and the same is true for the control event. The way to solve the problem is

2. When mediaplay is used, some events added, such as setoncompletionlistener, do not work and do not execute. The reason is that the data source has not been set before. The solution is to set the event response after setdatasource.

Mediaplay throws an IllegalStateException when executing prepare, which may be caused by uninitialized mediaplay. The solution can first execute stop and then analyze.

After mediaplay executes release, it is better to set it to null, such as:

It is best to set setonerrorlistener for error listening, and reset when an error occurs. Because some errors cannot be avoided, such as error (- 38,0), error (1, - 2147483648)

3. If you want to make a control obtain the default focus after the page is loaded, after calling requestfocus(), if it doesn't work, you can add a sentence setfocusableintouchmode (true), which may not be reflected visually because it is not accessed through the keyboard when entering the application;

4. The exception of the left window is caused by the fact that the dialog may not be closed when the activity is closed. Scenario: throw an exception on a non main thread and directly exit the activity, resulting in no closure of the dialog. Solution: close the dialog in ondestroy; Analyze whether your non main thread has code to change the UI. This modification method should be analyzed in detail.

5. ProgressDialog changes the rotated image

ProgressDialog. Setindeterminatedrawable (drawable drawable), drawable is written in XML file, as follows:

6. linearlayout weight

Layout of child elements_ For the weight attribute, the smaller the value, the greater the proportion. There are two cases:

For example:

If displayed horizontally, the layout of child elements_ The width property value is fill_ Parent, then layout_ The smaller the weight attribute value, the larger the display proportion, and the layout_ The width attribute value is wrap_ Content, then layout_ The smaller the weight attribute value, the smaller the display scale.

7. If the startup mode of an activity is set to singletask or singleinterval, its onactivityresult will lose its function unless the property is reconfigured

8. Android: fillafter = "true" does not work

The solutions are:

①. Set through Java code:

②. The configuration XML is written in the set tag, such as:

Points to note when animating Android:

①. To call the setBackgroundResource method of Imageview in code, if you set the SRC property directly in the XML layout file, FC will be triggered when the animation is triggered.

②. Stop () before the animation start (), or it will stop at the last frame after the first animation, so the animation will only be triggered once.

③. The last point is mentioned in SDK, do not call start in onCreate, because AnimationDrawable is not completely related to Window. If you want to start animation when you want to display the interface, you can call start () in onWindowFoucsChanged ().

9. When playing music through mediaplayer, it is said on the Internet that if it is played in the activity, the music will stop when the activity exits. This is pure fucking bullshit. I had no doubt about it before. When mediaplayer plays music, it will restart a service for playing. If your activity or service has been destroyed, it will not affect the life cycle of the playing service.

For more Android related content, readers who are interested can view the topics on this site: summary of Android view skills, summary of activity operation skills of Android programming, summary of SQLite database skills for Android, summary of JSON format data skills for Android, summary of Android database operation skills, summary of Android file operation skills Summary of SD card operation methods for Android programming development, introduction and advanced tutorial for Android development, summary of Android resource operation skills and summary of Android control usage

I hope this article will help you in Android programming.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>