Android Knowledge (ii)

Source: Internet
Author: User

Record Android fragmented knowledge points in the project for memo.

  • Asyncqueryhandler
    • Inheritance and handler, can be used to handle additions and deletions (data provided by ContentProvider)
    • For example: query = new Asyncqueryhandler (Getcontentresolver ());

      Include methods: Startquery, Startinsert, Startdelete, Startupdate:

      Uri uri = sms.convesation_uri; query.startquery (nullnullnull, "Sms.date desc") ;
  • Windowmanager.addview
    • Can implement the suspended window, the parameter is two: The former is a view, the latter is a parameter, the parameters of the WindowManager.LayoutParams.type indicate the type of the pop-up view:
    • More commonly used are: Type_system_alert system tips. It always appears on top of the application window
      Type_application General application Function program window

    • You can also animate new views in parameters, using. windowanimations = R.style.anim_view, and defining Anim_vew in Style.xml

    <style name= "Anim_view" >        //define        <item name= "@android: Windowexitanimation" in the Anim folder >@ Anim/out</item>    </style>

      • edittext has focus (focusable is true) prevents the IME from popping  

edittext=(EditText) Findviewbyid (r.id.txtbody);        Edittext.setontouchlistener (new  Ontouchlistener () {                         publicBoolean OnTouch (View V, motionevent event) {                  //  turn off soft      keyboard                return  False;            }        
      • Block Input Method Popup when Eidttext (Focusable=false) is not in focus
Inputmethodmanager IMM =
(Inputmethodmanager) Getsystemservice (input_method_service); 0);
      • If the input method is already displayed on the window, it is hidden, and the inverse is displayed
Imm.togglesoftinput (0,hide_not_always);
      • Input method is single open
boolean isopen=imm.isactive (); // IsOpen returns True to indicate that the input method is open
  • Handler's Removemessages
    • Handler the removemessages (int) application, delete the message msg.what = Int. Usually used in conjunction with sendmessagedelayed. Scenarios: such as handling keystrokes frequently.
  • ANR problem
    • Tip Application not responding,android prompts the user that the app is unresponsive, waiting, or terminating.
      In Android, the responsiveness of the application is monitored by the activity Manager and the WindowManager system service. ANR is triggered when it detects the following conditions:
      1. No events in response to input within 5 seconds
      2.BroadcastReceiver did not complete in 10 seconds
      The note here is to start a new service processing download, but the download task still has to be started separately because the service is also running on the main thread, which can cause the ANR problem.

  • Service or Thread
    • The surface thread can do all of the service, and there is no problem blocking the UI. But for Android, the service priority
      Higher than the background suspended activity, and the thread created by the activity. Therefore, as an important component of Android, it is used to perform background tasks.

  • Application applications
    • You can implement some initialization tasks for the entire app in OnCreate, which will only be executed once, such as broadcast monitoring
    • The application life cycle is the application itself, so you can also save some global variables in application
  • .9.png
    • .9 types of images are a special image format for Android, which supports arbitrary stretching, which is not a simple pixel enlargement, but takes into account the contents of the picture
    • The Draw9patch.bat tool can be made in Android.

Android Knowledge (ii)

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.