Detailed explanation of multiple windows in the android Browser

Source: Internet
Author: User

Android browser provides a detailed introduction of many window solutions. For more information, see

The Android platform is composed of one Activity and one or more views.
Therefore, when we want to display an interface, we first think of creating an Activity and implementing all the operations in the Activity, or a Dialog or Toast. This method is simple, but in some cases, we only need simple display. It is obviously redundant to use Activity. What should we do at this time?

An Android application is also a linux Process at the underlying layer, but the process concept is weakened at the upper layer, and Activity interaction is abstracted. The Code directly controls Activity, and user interaction is also Activity.
Activity is an object abstracted from the perspective of user interaction. It is isolated from processes in terms of concept and usage. A process is similar to an adoption function. A process can have multiple activities, not only the Activity of its current application can be adopted,
You can also use another installation package to specify the Activity of the process. The Activity is destroyed and the process is not destroyed (unless the system needs or the code forces the process to be killed ).

Originally, the window mechanism of the entire Android system is based on a WindowManager interface that allows you to add a view to the screen,
You can also delete a view from the screen. It targets the screen at one end of the object and View at the other end, directly ignoring our previous Activity
Or something like Dialog. In fact, the underlying implementation of our Activity or Diolog is also implemented through WindowManager.
WindowManager is global, and the entire system is the only one. It is the bottom layer of the display View.

Write a simple code:
Java code

Copy codeThe Code is as follows:
WindowManager mWm = (WindowManager) getSystemService (Context. WINDOW_SERVICE );
Button view = new Button (this );
View. setText ("window manager test! ");
WindowManager. LayoutParams mParams = new WindowManager. LayoutParams ();
MWm. addView (view, mParams );


Generally, an error occurs when you first develop android, that is, getWidth () and getHeight () are obtained in the View constructor (),
When a view object is created, android does not know its size. Therefore, getWidth () and getHeight () return 0,
The actual size is calculated only when the layout is calculated. Therefore, it is interesting to find that onDraw () can achieve the length and width.

Use WindowManager to implement floating windows

Copy codeThe Code is as follows:
WindowManager. LayoutParams params;

Params = new WindowManager. LayoutParams (
ViewGroup. LayoutParams. MATCH_PARENT,
ViewGroup. LayoutParams. WRAP_CONTENT,
WindowManager. LayoutParams. TYPE_PHONE, // TYPE_APPLICATION,
WindowManager. LayoutParams. FLAG_NOT_FOCUSABLE,
PixelFormat. TRANSLUCENT );
Params. gravity = Gravity. TOP;
Manager. addView (tmpView, params );

 
You can add the View that needs to be added to the floating window to the window:

Copy codeThe Code is as follows:
If (view. getParent = null) // if the view is not added to a parent component, add it to WindowManager.
WManager. addView (view, wmParams );


View is the view component that needs to be placed in the floating window.

To remove it from WindowManager, run the following statement:

Copy codeThe Code is as follows:
If (view. getParent ()! = Null)
WManager. removeView (view );


In android, you can add multiple windows as shown in the preceding method:

2. Application lifecycle issues
When other applications appear before the browser's main Activity, the browser's life cycle enters the onPause status no matter how many browser subwindows are popped up.

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.