Our Android platform is composed of one Activity after another. Each Activity consists of one or more Views.
So, when we want to display an interface, the first thing we think of is to create an Activity, and then all operations are implemented in the Activity, or it is a Dialog or Toast. This method is certainly simple, but in some cases, all we require is simple display, and using Activity is obviously redundant. At this time, how should we deal with it?
An Android application is also a Linux process at the bottom layer, but the concept of process is weakened at the upper layer and abstracts the interaction of Activity. The code directly controls the Activity, and the user's interaction is also the Activity.
Activity is an object abstracted from the perspective of user interaction, and is isolated from the process in concept and use. The process is similar to an adoption function. A process can have multiple activities. It can not only adopt the activity of its current application,
can also adopt the activities specified by other installation packages for the process. If the activity is destroyed, the process will not be destroyed (unless The system requires or code forces the process to be killed).
It turns out that the entire Android window mechanism is based on an interface called WindowManager. This interface can add views to the screen and
can also delete views from the screen. The object it faces is the screen on one end and the View on the other end, directly ignoring our previous Activity
or Dialog and the like. In fact, the underlying implementation of our Activity or Diolog is also through WindowManager. This
WindowManager is global, and the entire system is the only one. It is the bottom layer that displays the View.
Write a simple code:
Java code
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 when you first start developing android, you will make a mistake, that is, get getWidth() and getHeight in the constructor of View (),
When a view object is created, android does not know its size, so the results returned by getWidth() and getHeight() are 0,
The real size is calculated when the layout is calculated, so it will I found an interesting thing, that is, the reason why the length and width can be obtained in onDraw().
Use WindowManager to implement floating windows
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:
if(view.getParent==null)//如果view没有被加入到某个父组件中,则加入WindowManager中 wManager.addView(view,wmParams);
Among them, view is the view component that needs to be placed in the floating window.
If you want to remove it from WindowManager, you can execute the following statement:
if(view.getParent()!=null) wManager.removeView(view);
In android, you can add multiple windows according to the above method. Problems caused by multiple windows:
2. Application life cycle issues
When other applications appear before the browser's main Activity, no matter how many browser sub-windows pop up in front, the browser's life cycle will enter the onPause state.
For more detailed explanations of multi-window solutions for android browsers, please pay attention to the PHP Chinese website!

This article analyzes the top four JavaScript frameworks (React, Angular, Vue, Svelte) in 2025, comparing their performance, scalability, and future prospects. While all remain dominant due to strong communities and ecosystems, their relative popul

The article discusses implementing multi-level caching in Java using Caffeine and Guava Cache to enhance application performance. It covers setup, integration, and performance benefits, along with configuration and eviction policy management best pra

Node.js 20 significantly enhances performance via V8 engine improvements, notably faster garbage collection and I/O. New features include better WebAssembly support and refined debugging tools, boosting developer productivity and application speed.

Java's classloading involves loading, linking, and initializing classes using a hierarchical system with Bootstrap, Extension, and Application classloaders. The parent delegation model ensures core classes are loaded first, affecting custom class loa

This article addresses the CVE-2022-1471 vulnerability in SnakeYAML, a critical flaw allowing remote code execution. It details how upgrading Spring Boot applications to SnakeYAML 1.33 or later mitigates this risk, emphasizing that dependency updat

Iceberg, an open table format for large analytical datasets, improves data lake performance and scalability. It addresses limitations of Parquet/ORC through internal metadata management, enabling efficient schema evolution, time travel, concurrent w

This article explores integrating functional programming into Java using lambda expressions, Streams API, method references, and Optional. It highlights benefits like improved code readability and maintainability through conciseness and immutability

The article discusses using Maven and Gradle for Java project management, build automation, and dependency resolution, comparing their approaches and optimization strategies.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

SublimeText3 Mac version
God-level code editing software (SublimeText3)

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

Notepad++7.3.1
Easy-to-use and free code editor

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.
