Android development issue summary

Source: Internet
Author: User

1. When installing Android SDK with installler (SDK starter package), the system prompts that JDK cannot be found, but JDK has already been installed on the machine.

One effective solution for many people is to click the "back" button and then click "Next" to find the JDK. Reference

But this method does not work on my machine. So I chose not to use installer, but to download a zip file. After decompression, run SDK manager.exe. Reference

2. Create an android project in eclipse and prompt "cocould not find xxx.apk!" when running/debugging !"

Most of the solutions mentioned on the Internet are clean the entire project, or select the fix project properties menu item. But it does not work for my environment.

After upgrading to eclipse 3.7, the newly created Android project reports an exception "Sun/security/X509/x500name" in the build phase. It is suspected that it is related to the JDK used (ibm jdk 6. Sure enough, the problem is solved after you uninstall ibm jdk and install Sun JDK.

3. LetProgramAdapt to different screen resolutions

For details, refer to the following link: Android screen resolution.

4. Use 10.0.2.2 In the android simulator to access the host machine.

5. In the setwidth () method, the specified width is in pixel units. How to convert it to the unit of Using Dip (device independent pixels?

Use the followingCode, Reference

// Converts 14 dip into its equivalent PX

Resources R=Getresources ();
FloatPx=Typedvalue. applydimension (typedvalue. complex_unit_dip,14, R. getdisplaymetrics ());

6. usage of the pop-up dialog box. This link is described in detail.

7. You need to sign the exported APK file. This link is detailed.

8. for Android interface design principles, refer to this link.

9. Using merge instead of layout can reduce the number of layout while avoiding repeated layout writes.

10. USB debugging on a real machine is much faster than AVD debugging. The setting is also very simple. See this link. However, 10.0.2.2 cannot be used, and the real machine can access the servers in the LAN through WiFi.

11. Android-ui-utils is a good online Android icon generator. The address is here.

12. If an inexplicable NULL pointer error occurs during debugging, for example, if findviewbyid () returns NULL, try to clean the entire project first, which can be solved normally.

13. display a row of information when there is no data in the listview.

Refer to the link and pay attention to the ID of listview and textview.

14. Use your own icon to replace radiobutton in listview.

Add an image to layout as the row, overwrite the getview () method of the adapter in Java code, and set the visibility of the Image Based on the getcheckeditemposition () result of listview. Do not use the setonclicklistener () method to set the image visibility in the view. Because listview only maintains the visible row controls, this will lead to a very strange result (the second record of the first record result is selected, and the selected status will change randomly when you scroll the listview ).

Another method is to set checkmark as the required icon through style, which may be a simpler solution (not yet try ).

UPDATE: The above results are based on the situation that you do not know about the listview implementation. In fact, radiobutton can be used, see #22.

15. The selection and choice of listview are completely different, so do not expect listview # clearchoice () to be clear about the items in the checked state.

16. When the screen direction changes (landscape screen-> portrait screen, or vice versa), the changed content in the listview is lost and the status returns to the beginning.

When the screen direction changes, Android will recreate the entire activity so that you can construct a UI that is more suitable for a specific direction. To avoid this problem, add Android: configchanges = "orientation" to the activity declaration in androidmanifest. xml. For more information, see the reference link.

17. Download Links for various mobile phone platform Simulators/simulators.

18. The alertdialog # Show () method does not block the current thread.

19. allow communication between different activities. For example, if one tabactivity contains multiple activities, some messages must be transmitted between them.

You can use the broadcastreceiver mechanism. Reference link. Note that messages cannot be received when the tab is not started. Therefore, messages must be received in the activity where the tabhost is located and sent to the tab when it is started.

20. Style and theme documents in Android SDK

See this link.

21. Tab style.

There are many issues with the tab style of Android, and different versions of the style are different. Here is a reference link for custom styles.

22. Use the single-choice/Check button in listview.

There are many problems. This link seems to have solved the problem, but it was not tested successfully in my environment.

Update: take the check button as an example. The essential problem is that the check button in the listview does not know which model is. You need to associate it with checkbox # settag (mymodelobject) in advance, in The onclick event, use gettag () to change the selected status. We recommend that you read this document.

23. Add parameters to the strings defined in strings. xml.

Use "% 1 $ s" and "% 2 $ D" in the string to represent the sequence number and type of the parameter, and then assign values using the string. Format () method. Refer to this link.

24. Embedded barcode/QR code scanning

Use zxing. The scanner first installs barcodescanner.apk on the mobile phone, and then calls the activity provided by it in the program. The activity will return the scan result. Reference

25. Change the background color of each row in the listview.

You cannot write view. setbackgroundcolor () directly in getview. The correct method is to first create an XML file in the drawable directory and name it as my_row.xml. The content is as follows (the key is the first and fourth <item> ):

 <?  XML version = "1.0" encoding = "UTF-8"  ?>  <  Selector  Xmlns: Android  = "Http://schemas.android.com/apk/res/android"  >      < Item  Android: state_window_focused  = "False"  Android: state_selected  = "True"  Android: drawable  = "@ Android: color/transparent"   />      <  Item  Android: state_selected  = "True"  Android: drawable  = "@ Android: color/transparent"   />     <  Item  Android: state_pressed  = "True"  Android: state_selected  = "False"  Android: drawable  = "@ Android: color/transparent"   />      <  Item  Android: state_selected  = "False"  Android: drawable  = "@ Color/solid_red"  />  </  Selector  >  

Then write it in getview () as follows:

 
 If(Item. getstopid (). Equals (user. stopid) {view. setbackgroundresource (R. drawable. my_row );}Else{View. setbackgroundresource (Android. R. drawable. list_selector_background );}

Reference link 1 Reference link 2 reference link 3

26. In a tablelayout, make the button of the same width and fill the table width (imagine a nine-phase grid composed of buttons)

If the text on the button is not long, it can be implemented in the general method, such as this link. When the text on the button is long, it will still cause layout accidents, and the length of each column will be different. The solution is to set the layout_width of the button to 0 and the layout_height to the desired value, set singleline to false in a different line, and set the gravity of the button to center.

27. Handling of screen Switching

Refer to a typical discussion on stackoverflow.

When myactivity is in a tabactivity, I did some experiments to show whether tabactivity declares Android: configchanges = "keyboardhidden | orientation" is irrelevant to myactivity, the onconfigurationchanged () method is triggered only when myactivity makes the preceding Declaration.

28. When strings in strings. xml contain HTML tags

<DATA> <! [CDATA [...]> </data> pack HTML code. Reference

29. When listadapter (such as arrayadapter) is used in alertdialog, the text is not displayed.

The resourceid of the view must be select_dialog_singlechoice, but not simple_list_item_single_choice. Otherwise, the text color is the same as the background color and cannot be displayed. Reference

30. how to configure third-party packages in Android

The link is successfully referenced.

31. Customize the appearance of tabhost

There are many requirements and problems online. The main solutions are tabhost-based and radiobutton-based. Here are several links for reference. Link 1, link 2, link 3

32. Get the current screen direction

There are several methods to get the orientation value, but some of the obtained values are incorrect, such as getwindowmanager (). getdefaultdisplay (). getorientation () and getreqestedorientation (). Getresources (). getconfiguration (). orientation is a reliable experiment.

33. When the first view in the activity is edittext, the keyboard automatically pops up.

It seems that some models will do this. To prevent the keyboard from popping up, add a line of code to oncreate. Reference

 
 This. Getwindow (). setsoftinputmode (windowmanager. layoutparams. soft_input_state_always_hidden );

34. Theme of Dialog

When theme. light is used, the dialog display is abnormal. Related discussion: link 1, link 2

35. differentiate onclicklistener and oncheckedchangelistner of checkbox and radiobutton.

When the former is used, when mycheckbox. setchecked (true) is executed in the Code, the event will not be triggered, while the latter will trigger the event.

36. Monitor GPS enable/disable events

Gpsstatus. Listener is not reliable (events cannot come up). This link is used to monitor events in settings: Reference Link

37. horizontal screen of the simulator

Press Ctrl + F11. Some people mentioned that Ctrl + F12 and numpad 7 can also be used, but it does not work here.

38. Some problems may occur when the Java code corresponding to kml is generated using jaxb. The solution is as follows:

1) Write a binding file such as bindings. xjb in the same directory as ogckml22.xsd. For details, refer to this link (delete several lines according to the error message)

2) Add-extension to the command line.

3) Add-target 2.1 to the command line (otherwise, the annotation of the generated Java class carries the keyword "required" not recognized by JDK 6 ")

The complete command line is as follows:

 
Xjc-XMLSCHEMA-verbose-extension-B bindings. xjb-D Src-target 2.1 ogckml22.xsd

39. entryvalues of listpreference can only use string-array

If integer-array is used, a null pointer exception occurs when you click this preference item. For details, see link 1 and link 2.

Update: A New listpreference problem is found, that is, the defaultvalue cannot be too large (beyond integer. max_value) integer; otherwise, defaultvalue does not work (the option is not selected by default ). There are many problems. Android 2.2.

40. Android provides a convenient share mechanism, but generally share text to Weibo or SMS. How can I "share" text to an SD card file?

This link describes the same question, waiting for someone to answer. The current idea is to implement an activity that accepts action_send in the program. For more information, see this link or this article.

41. A website that views kml files online for your reference.

GPS visualizer

42. Usage of onsaveinstancestate ()

Usually works with oncreate () instead of onrestoreinstancestate (). Refer to this link.

43. clicking an item in listview does not change the background color to orange (default feedback color), and various onclick events are not triggered.

One possibility is that the following attributes are used in the layout file of the item (such as foo_list_row.xml) (automatically scrolling text is often used). After this attribute is removed, it can be restored to normal:

 
Android: ellipsize = "marquee" Android: scrollhorizontally = "true"Android: marqueerepeatlimit= "Marquee_forever" Android: focusable = "true"Android: focusableintouchmode= "True"

44. Implement a non-stop scrolling listview

Suppose you have a long list that needs to be automatically displayed by rolling up a row every several seconds. It is a bit similar to the marquee function of textview ?). This requirement can be implemented through handler. For details, refer to this link. when the list is rolled to the last row, It is very stiff to roll back to the first line. You can use the solution provided in this link.

45. Add an image next to the button text

In <button>, use Android: drawableleft = "@ drawable/my_icon" Android: gravity = "Left | center_vertical". Similarly, you can add it to the right or the upper and lower sides. However, if the button has other states, you must use selector to specify images in different States. In addition, the image size is not automatically adjusted according to the button.

46. Compatibility with old versions

See this article in the SDK documentation.

47. easily implement the rounded corner background

You do not need to create a rounded corner image. It is very convenient to look at this link. Change angle to a multiple of 45. Otherwise, an error is returned.

48. Android Memory leakage detection

You can view heap usage in ddms to check whether memory leakage exists. Ddms can also dump out the. hprof file, which can be opened with eclipse mat to further analyze the cause of the error. Note: After startactivity (), you must determine whether to call the finish () method based on the actual situation (if back is required, do not finish (), and use flag_activity_clear_top to reclaim the memory space at the appropriate time ), activities that do not finish () will always occupy the memory.

49. Third-party library of Android

This link summarizes a lot.

50. Android UI design mode

Refer to this link.

51. Use of Google map extension.

Refer to this link.

52. When the spinner is in invisible state, it seems that calling myspinner. setselection (I) will not trigger its onitemselected () event.

53. When compressing the JSON object returned by the gzip server, pay attention to response. setcontenttype ("application/JSON"), and. you can only set application/JSON to compressablemimetype in XML. I wasted three or four hours for the previous reason.

54. Theme customized for the alertdialog. Builder application

Use contextthemewrapper. For usage, refer to this link. However, it was later found that this method does not work. There is a saying that this method is only valid for some Android versions, and it is also said that it is useless (all on so ). Use alertdialog. the setview () method of builder is also problematic, because you will find that it is black next to this view (assuming that your view is a light background), and the effect is very poor. In fact, to set the dialog box to a white background, you can use the setinversebackgroundforced (true) method of alertdialog. Builder, which is very simple and straightforward.

55. Select some available image parameters from gallery

Refer to this link and related issue (the file cannot get the original image, only the reduced image can be obtained ).

56. When retrieving images from gallery, note that the memory is limited, and the image may be large.

Use insamplesize to help solve the problem. Refer to the code of this link.

57. When the program process is killed by the system (usually when the memory is tight ):

The session of httpclient can be retained in the persist mode;

We recommend that you keep the remaining data in sharedpreferenes;

In onactivityresult (), you can obtain the parameters in the intent passed back by another activity;

58. When connecting to the real machine, the message "unable to open sync connection" is displayed!

The cause is unknown. The solution is to remove USB debugging from the settings of the real machine, and then re-check.

59. Get the GPS status (Star searching or acquired location)

This problem seems simple, but the locationlistener # onstatuschanged () method in Android does not work normally, as it is not called in most versions. The method provided in this link seems to be usable.

60. Draw a Statistical Chart (bar chart, pie chart, etc.) in Android)

This link provides a number of solutions. I have selected achartengine for the moment. Its usage is similar to that of jfreechart. There are many parameters and the current activity is good.

61. The process is often killed.

You can consider starting a service so that the process becomes "important" and therefore cannot be killed easily.

62. Error in "author Er not registered"

If you have not registered a mycycler before executing the unregisterreceiver (mycycler) method, this exception is thrown. Reference

63. When an application runs in the background, an error is reported in a dialog box (for example, when an event is triggered from the Service): "badtokenexception: unable to add window"

Use isfinishing () to test whether the activity is in the background. For more information, see

64. Is emulator too slow?

Try Android x86, which is said to be much faster than the official version (I have not tried it yet and I am downloading it ). Reference

65. Disable automatic switching to Landscape mode
<ActivityAndroid: Name= ". Someactivity"Android: Label= "@ String/app_name"Android: screenorientation= "Portrait">...</Acivity> 

Reference

66. Several crowdsourcing testing platforms

Testflight is the most famous iOS platform. Other similar test platforms support Android. For details, refer to this link.

67. Black screen after locking, but no screen is displayed

 
Getwindow (). addflags (windowmanager. layoutparams. flag_show_when_locked );

Another functional flag is flag_dismiss_keyguard. The difference is that the flag is only valid for the current activity, and the latter is globally valid. In addition, the former is also effective for secure lock screen, while the latter is only effective for normal lock screen. A reference link is provided.

But there is a problem with the former, that is, the screen lock page may flash when switching between the two activities with flag_show_when_locked set. See this issue report.

68. Some tools for Android app performance testing and Memory Leak Detection

See this link.

69. a bug in the progress bar

The progress percentage displayed after resetting setmax () is incorrect, at least in Android 2.1 (API level 7. See this link and this link.

70. When a listview item contains controls (such as buttons and check boxes), this item cannot be selected.

Android does not allow you to select items with the focusable element in the listview. The solution is to set the focusable attribute of the control to false. Reference

71. A Tool for simple Web Testing (constructing and sending various HTTP requests)

This link summarizes a lot.

72. Place the tab on the bottom (like the iPhone style)

I have read several Chinese tutorials, but they are not reliable. A link on so can be done, or a tutorial with source code.

73. headerview/footerview is displayed when listview has no data

The trick is to make empty view contain headerview/footerview. See this link.

74. Add popup on Google Map

For the simplest method, see this link.

75. A website can search for the code and resources of Android-related projects.

Link here

76. The search activity in Android does not support returning results to the activity that calls the result (because the onsearchrequested () method does not call startactivityforresult () to start the search activity)

So has a number of posts asking this question, such as link 1 and link 2. There is no particularly convenient solution, for a method that I have never tried but should be feasible, see this link.

77. Tools for viewing APK File Content

Apktool is recommended as a command line tool. Its usage is as follows:

 
> Apktool. Bat D my.apk

All resource files can be restored, but. java files cannot be restored.

78. standard size of various icons used in Android

See the built-in guideline document of the SDK.

79. The searchable interface of Android does not allow callers to obtain query results.

You can refer to this document for implementation. The idea is to use startactivityresult () to start the search interface, and then retrieve the result from onactivityresult. My test is feasible, but there are two errors in this document:

1) handleintent () instead of handleactivity ()

2) intent. setaction (intent. action_search) before startactivityresult.

In addition, pay attentionArticleThe official documentation mentioned in implements the newintent () and oncreate () methods, and sets the Android: launchmode = "singletop" of the caller in androidmanifest. xml ".

80. This is a strange problem. Sometimes edittext cannot be used to input text (the keyboard is normal, but the character cannot enter the text box). You must switch to another input method to enter the text.

After testing, some models have this problem, and the specific cause is unknown. The following link may be related to this: link 1

81. execute a program at regular intervals

You can use alarmmanager with broadcastreceiver to execute functions such as alarm clocks. There are many examples on the Internet that will not be described here. It is worth mentioning that in this broadcastreceiver, do not perform asynchronous operations (for example, access a remote Service asynchronously and obtain the current location), because once the onreceive () method is executed, the process used to hold broadcastreceiver may be killed by the system at any time, resulting in exceptions after the asynchronous operation ends. The solution is to start a service in the onreceive () method (startservice is used, and the bindservice method may also work), and execute any operation in the service. Refer to broadcastreceiver Life Cycle

82. Monkey Test

 
> ADB shell monkey-v-P com. My. app 100

Monkeyrunner can perform more advanced tests.

83. Data in extras cannot be cleared with getintent (). getextras (). Clear ()

The reason is that getextras () returns a copy instance, which can be cleared one by one using getintent (). removeextra. Reference

84. When alertdialog is used to implement the input dialog box, if the builder. setview (myedittext) text box is too long.

You can use dialog. setview () to specify padding (note that it is dialog. setview () rather than builder. setview (). For details, see this link.

85. display images in textview

You can use the HTML. fromhtml () method to display HTML text in textview, but only some tags are supported:

 
Mytextview. settext (html. fromhtml (myhtmlstr ))

To display a remote image in textview, you must provide an imagegetter object to the fromhtml () function, obtain the remote image in its getdrawable () method, and convert it to the drawable type. See this link for sample code.

If the Android: linespacingmultiplier attribute is set in textview, the image is displayed incorrectly (some blank spaces are displayed on the top). This problem is not found when the Android: linespacingextra attribute is used.

If the image loading speed is slow, the entire textview will be blank for a long time. To solve this problem, the image needs to be loaded asynchronously, so that the text can be displayed first. After the image is downloaded, the text is added to the middle. The implementation method is to expand drawable. For details, refer to the two links: link 1 and link 2. The scheme of link 1 has the problem that the image size is incorrect because textview # invalidate () failed to work (unknown reason). Use the method provided by link 2 to solve the problem. This link uses textview. settext (textview. gettext () can also work, but I didn't try it.

86. display the list (<li> label) in textview)

Android textview only supports a small part of HTML tags (see this link). By default, list tags such as <ol>, <ul>, and <li> are not supported. You can use taghandler to implement a simple list (see this link), but this method has a serious problem: when the list text exceeds one line, the text in the second line is the unindent effect of the top header (see this question), and there is no good solution for this problem.

(To be continued)

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.