Android Common Knowledge Enumeration

Source: Internet
Author: User

  1. When activity is visible, the page refreshes, that is, at the top of the activity stack, of course, the refresh operation can be in Onstart,onresume,onrestart,onnewintent+singletask, but the best place is Onresume, Other ways may cause the form to leak

  2. The two ways to start the service, StartService and Bindservice, depending on the way the boot is different, of course there is a way called composite startservice+bindservice,service destruction, StartService can do the background service after the app exits , but bindservice not, Startservice+bindservice can also do after the app after the back-end service, But the app must be unbind when exiting, in turn Bindservice+startservice can't do the service after the app exits

  3. It is recommended that you add a variable activityisactivity to the activity to determine whether the current activities are active, change their values in Activity::onresume and Activity:onpause, Prevents form leaks from occurring when there is no interface.

  4. Monitoring the change of focus in the Onwindowfocuschanged method of activity

  5. Use inputmethodmanager the most flexible way to exit the keyboard is

    inputmethodmanager imm =  (Inputmethodmanager) Getsystemservice (Context.input_method_service); boolean isopen=imm.isactive ();// IsOpen returns true to indicate that the input method opens if (IsOpen) {    imm.hidesoftinputfromwindow ( MainActivity.this.getCurrentFocus (). Getwindowtoken (),  inputmethodmanager.hide_not_always);       //(Widgetsearchactivity is the current activity)} 

    Of course, if the page will only have a edittext that can start the keyboard, You can replace MainActivity.this.getCurrentFocus () directly with the space

  6. Dip to px formula is px = Dip*scale+0.5f,scale is density, of course, can also use (int) typedvalue.applydimension (typedvalue.complex_unit_px, 20, Context.getresources (). Getdisplaymetrics ());

  7. There are 2 ways to get Displaymetrics, GetWindow.getWindowManager.getDisplayMetrics (Displaymetric DM), and one is Context.getresources (). Getdisplaymetrics (), which is more flexible to use, it is recommended to use the latter

  8. Customize permissions + references + Use custom permissions by customizing <permission android:name= "Custom Permissions" android:protected= "based on security level settings, if confidentiality is high, use the signature method"/> Then quote <use-permission android:name= " custom permissions "/>, use custom permissions as follows

    <receiver android:name= ". Smsbroadcastreceiver "android:export=" false "android:permission=" Custom Permissions "> <intent-filter android:priorit y= "> <action android:name=" Android.provider.Telephony.SMS_RECEIVED "/> </inten T-filter> </receiver>
  9. Android:export Indicates whether the component is called across processes, the default is False,Android:windowsoftinputmode indicates a change in the keyboard popup UI layout and defines the keyboard popup state, when the popup behavior

  10. Android:nohistory indicates that the component is not displayed in (the most recently opened list ), and Android:configchanges indicates that the activity program does not restart when the specified change occurs. The response changes are also obtained through onconfigurationchanged, android:screenoriention indicates what screen state the activity should be in, Android:lanchemode is the specified creation mode

  11. Force detection of permissions issues across process calls

    public Boolean isenable () {mcontext.enforcecallingorselfpermission (Android.    Manifest.permission.WAKE_LOCK, "You donot has the Wake_lock permission");    LOG.D ("pid=" +binder.getcallingpid () + ", uid=" +binder.getcallinguid ()); return isenableinternal ();}


  12. <use-library> connected shared libraries needed for life,<use-feature> the hardware environment support required by the Life app, such as Bluetooth support, or the app will fail to install.

  13. The difference between Android:cleartaskonlaunch and Android:finishontasklauch is that the former knows the activity outside of itself, and the latter clears the activity Task from the background. The latter is more commonly used.

  14. Each app is assigned a virtual machine process, so you don't want all of the JVM's apps to share the same virtual machine process

  15. Use Localbroadcastreceiver or Myview.gethandler for Message Queuing updates, and statically inherit Handler when customizing Handler. Otherwise, it may be because the activity held by handler cannot be destroyed, because handler itself holds a static object, his life cycle is the same as the app, so in order for the activity to be destroyed in time, the public static class must be statically inherited MyHandler extends Handler


Android Common Knowledge Enumeration

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.