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
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
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.
Monitoring the change of focus in the Onwindowfocuschanged method of activity
-
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
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 ());
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
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>
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
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
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 ();}
<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.
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.
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
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