In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article will explain in detail what are the unpopular knowledge points about Android. The editor thinks it is very practical, so I share it for you as a reference. I hope you can get something after reading this article.
Four major components are related:
1. To start an Activity, at least two binder threads are required in the application process.
two。 Start an Activity with a launchMode of singleTask, which does not necessarily run on the new Activity stack.
3. Activity of two different applications can run in the same Activity stack.
4. All Activity in the same application process share a WindowSession.
5. Popping up an AlertDialog does not necessarily require an Activity-level Context, and there is a way to pop up an AlertDialog anywhere, as long as it is after the attachBaseContext of the Application.
Here is a simple demonstration of demo:
First look at DemoApplication, then look at the Alert class:
Initialize in Application:
Import android.app.Application;public class DemoApplication extends Application {@ Override public void onCreate () {Alert.alertAnyWhere (); super.onCreate ();}}
The following class is a wrapper class for AlertDialog:
Import android.app.AlertDialog;import android.content.Context;import android.content.DialogInterface;import android.os.Build;import android.os.Handler;import android.os.Looper;import android.view.WindowManager;import java.lang.reflect.Method;public class Alert {public static void alertDialog () {Context mAppContext = null; try {Class clazz = Class.forName ("android.app.ActivityThread") Method method = clazz.getDeclaredMethod ("currentApplication", new Class [0]); mAppContext = (Context) method.invoke (null, new Object [0]);} catch (Throwable e) {e.printStackTrace (); return;} AlertDialog.Builder builder = new AlertDialog.Builder (mAppContext); builder.setTitle ("Hi") .setMessage ("Hello World") .setPositiveButton ("OK", new DialogInterface.OnClickListener () {@ Override public void onClick (DialogInterface dialog, int which) {dialog.dismiss () ) .setNegativeButton ("cancel", new DialogInterface.OnClickListener () {@ Override public void onClick (DialogInterface dialog, int which) {}}); AlertDialog dialog = builder.create () If (Build.VERSION.SDK_INT > = Build.VERSION_CODES.KITKAT) {dialog.getWindow () .setType (WindowManager.LayoutParams.TYPE_TOAST);} else {dialog.getWindow () .setType (WindowManager.LayoutParams.TYPE_PHONE);} dialog.show ();} private static Handler handler Public static void alertAnyWhere () {if (Looper.myLooper () = = Looper.getMainLooper ()) {alertDialog ();} else {if (handler = = null) {handler = new Handler (Looper.getMainLooper ()) } handler.post (new Runnable () {@ Override public void run () {alertDialog ();});}
6. You can start an Activity that is not displayed by setting the Activity theme android.R.style.Theme_NoDisplay, which is useful in some places where you need to transition.
7.Activity, Service, Receiver defaults to false when the action attribute of intent-filter is not configured, and true when the action attribute of intent-filter is configured. A little carelessness is likely to bury hidden dangers such as ultra vires and Intent.
8. When removing an App from the list of recently used applications, only Service has a magical onTaskRemoved callback, but it is not necessarily a callback, and it is also related to the stopWithTask attribute and so on.
9. All four components run on the main thread because they are instantiated in ActityThread (or Instrumentation); their lifecycles also run on the main thread because messages are sent from the Binder thread to the main thread through ActivityThread.H and then callbacks are performed.
The emergence of 10.TaskStackBuilder basically solves all the problems of constructing Activity fallback stack.
11.ContentProvider 's onCreate () method executes before Application's onCreate () method, and later than Application's attachBaseContext () method, so there is also a way to pop up an AlertDialog in ContentProvider's onCreate () (Ref. 5).
The context type in 12.BroadCastReceiver callback onReceive (Context context,Intent intent) varies greatly from scenario to scenario. The Context of statically registered receiver callback is ReceiverRestrictedContext, while the dynamically registered receiver may be Activity or Application.
13.ServiceRecord and BroadcastRecord are themselves Binder.
14. The same provider component name may correspond to more than one provider.
Related to Handler and Message:
1.MessageQueue.addIdleHandler can be used to perform certain operations when the thread is idle, which is more suitable for operations that need to be performed in the future but do not know how much delay time needs to be specified.
2.Message.what should not be set to 0 as far as possible, because the postRunnable method will generate a message with a Message.what of 0. If the Message with a what of 0 is deleted, the Message created by the runnable method will also be deleted.
3.Handler can set synchronous async (the default is synchronous). The difference between them is that asynchrony is not blocked by Barrier, while synchronization is blocked.
The message distribution process of 4.Handler is that if the callback of Message is not empty, it is processed by callback. If the mCallback of Handler is not empty, it is processed by mCallback. If the first two are empty, handleMessage is called to handle it. In DroidPlugin, this feature of ActivityThread.H is used to intercept some messages and realize the plug-in of Activity.
The creation sequence of Looper and MessageQueue of 5.Java layer and Native layer is Java layer Looper- > Java layer MessageQueue- > Native layer NativeMessageQueue- > Native layer Looper.
The 6.Java layer sends messages through Handler, while the Native layer sends messages through Looper.
Related to Window and View:
1. Hardware acceleration can only be turned on and off at Window level, and can only be turned off at View level.
two。 Since android2.3 removed MidWindow, PhoneWindow has become the only implementation class for Window.
Four Binder are involved in the process of managing Window by 3.WMS, and there is only one Binder server of ViewRootImpl.W in the application process.
4.MotionEvent, KeyEvent, DragEvent, and others have similar chained caches, similar to Message.
5. In the process of saving and restoring the state of View, all View in ActionBar share a SparseArray container, and all View in ContentView share a SparseArray container. The View that is currently in focus will be stored extra.
6. A series of snooping methods for setting ViewTreeObserver need to make sure that View is after attachToWindow, otherwise memory leaks may occur because add snooping and remove snooping are not acting on the same object.
Related to Binder, IPC, process, etc.
1. File locks can be used to achieve inter-process mutual exclusion (see RePlugin), which is useful when dealing with tasks that only need to be performed by a single process.
In the 2.Binder design architecture, only the Binder main thread is actively created by this process, and the Binder ordinary thread is passively created by the Binder driver according to the IPC communication requirements.
Both 3.oneway and non-oneway need to wait for a response message (BR_TRANSACTION_COMPLETE) from Binder Driver, except that oneway does not have to wait for a BR_REPLY message.
The main thread of 4.mediaserver and servicemanager is binder thread, but the main thread of system_server is not Binder thread. The main thread of system_server is the same as the application process.
5. Multiple death callbacks can be registered in the same BpBinder, but Kernel is only allowed to register death notifications once.
6. The application process is hatched by the Zygote process. Before it really becomes the application process, the system cleans up the stack frame by throwing an exception and reflects the main method that calls ActivityThread.
7. In the process of Binder communication, the data is written directly from the user space where the communication process is initiated to the kernel space of the target process, and the data release in the kernel space is controlled by the user space.
This is the end of this article on "what are the unpopular knowledge points of Android?". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.