Android Browser multi-window scheme detailed

Source: Internet
Author: User
Android Browser multi-window scheme detailed introduction, need friends can come to refer to the next

Our Android platform is composed of one activity after another, each activity having one or more view compositions.
So, when we want to display an interface, the first thing we think of is to create an activity, and then all the operations are implemented within the action, or a dialog or toast. This approach is simple, but in some cases, what we require is simply to show that activity is obviously superfluous, and how do we deal with it at this time?

One application of Android at the bottom is also a Linux process, but at the top it weakens the concept of the process, abstracting the activity as an interaction. The code controls the activity directly, and the user's interaction is the activity.
An activity is an object that is abstracted from the point of view of user interaction and is isolated in concept and usage and process. Process is similar to an adoption function, a process can have multiple activity, not only can adopt their current application,
You can also adopt other installation packages The activity,activity that is assigned to the process is destroyed and the process is not destroyed (unless the system requires or the code forces a Kill process).

Originally, the entire android window mechanism is based on a called WindowManager, which can add view to the screen,
You can also remove view from the screen. It targets the screen at one end and the view at the other end, ignoring our previous activity directly.
Or dialog and stuff like that. In fact, our activity or diolog the bottom of the implementation is also through the WindowManager, this
WindowManager is the global, the whole system is the only Dongdong. It is the bottom of the display view.

Write a simple code:
Java code

Copy Code code 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);


Typically, when you start developing Android, you make the mistake of getting getwidth () and GetHeight () in the view constructor.
When a View object is created, Android does not know its size, so getwidth () and GetHeight () Return the result is 0,
The real size is calculated when the layout is computed, so it is interesting to find that the reason for the OnDraw () is that it can achieve a long width.

Using WindowManager to implement a floating window

Copy Code code 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 you want to add to the suspension window to the window:

Copy Code code as follows:


if (view.getparent==null)//If view is not added to a parent component, join WindowManager


Wmanager.addview (View,wmparams);


Where view is the viewing component that needs to be placed in a floating window.

If you want to remove it from WindowManager, you can execute the following statement:

Copy Code code as follows:


if (view.getparent ()!=null)


Wmanager.removeview (view);


Android can add multiple windows in the above method, and multiple windows will cause problems:

2. Application Lifecycle Issues
when other applications appear before the browser master activity, the browser's lifecycle enters the OnPause state regardless of how many of the browser's child windows have been ejected before.

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.