Added in [API level 19](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels) Summary: [Nested Classes](https://developer.android.com/reference/android/hardware/display/VirtualDisplay#nestedclasses) \| [Methods](https://developer.android.com/reference/android/hardware/display/VirtualDisplay#pubmethods) \| [Inherited Methods](https://developer.android.com/reference/android/hardware/display/VirtualDisplay#inhmethods)

# VirtualDisplay

*** ** * ** ***

` public final class VirtualDisplay `   
` extends https://developer.android.com/reference/java/lang/Object ` ` `

|---|---|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object) ||
| ↳ | android.hardware.display.VirtualDisplay |

<br />

*** ** * ** ***

Represents a virtual display. The content of a virtual display is rendered to a `https://developer.android.com/reference/android/view/Surface` that you must provide to `https://developer.android.com/reference/android/hardware/display/DisplayManager#createVirtualDisplay(android.hardware.display.VirtualDisplayConfig)`.

Because a virtual display renders to a surface provided by the application, it will be released automatically when the process terminates and all remaining windows on it will be forcibly removed. However, you should also explicitly call `https://developer.android.com/reference/android/hardware/display/VirtualDisplay#release()` when you're done with it.

<br />

**See also:**

- `https://developer.android.com/reference/android/hardware/display/DisplayManager#createVirtualDisplay(android.hardware.display.VirtualDisplayConfig)`

## Summary

| ### Nested classes ||
|---|---|
| ` class` | `https://developer.android.com/reference/android/hardware/display/VirtualDisplay.Callback` Interface for receiving information about a `https://developer.android.com/reference/android/hardware/display/VirtualDisplay`'s state changes. |

| ### Public methods ||
|---|---|
| ` https://developer.android.com/reference/android/view/Display` | ` https://developer.android.com/reference/android/hardware/display/VirtualDisplay#getDisplay()() ` Gets the virtual display. |
| ` https://developer.android.com/reference/android/view/Surface` | ` https://developer.android.com/reference/android/hardware/display/VirtualDisplay#getSurface()() ` Gets the surface that backs the virtual display. |
| ` void` | ` https://developer.android.com/reference/android/hardware/display/VirtualDisplay#release()() ` Releases the virtual display and destroys its underlying surface. |
| ` void` | ` https://developer.android.com/reference/android/hardware/display/VirtualDisplay#resize(int,%20int,%20int)(int width, int height, int densityDpi) ` Asks the virtual display to resize. |
| ` void` | ` https://developer.android.com/reference/android/hardware/display/VirtualDisplay#setRotation(int)(int rotation) ` Sets the rotation of the virtual display. |
| ` void` | ` https://developer.android.com/reference/android/hardware/display/VirtualDisplay#setSurface(android.view.Surface)(https://developer.android.com/reference/android/view/Surface surface) ` Sets the surface that backs the virtual display. |
| ` https://developer.android.com/reference/java/lang/String` | ` https://developer.android.com/reference/android/hardware/display/VirtualDisplay#toString()() ` Returns a string representation of the object. |

### Inherited methods

From class ` https://developer.android.com/reference/java/lang/Object ` ` https://developer.android.com/reference/java/lang/Object` ` https://developer.android.com/reference/java/lang/Object#clone()() `

Creates and returns a copy of this object.
` boolean` ` https://developer.android.com/reference/java/lang/Object#equals(java.lang.Object)(https://developer.android.com/reference/java/lang/Object obj) `

Indicates whether some other object is "equal to" this one.
` void` ` https://developer.android.com/reference/java/lang/Object#finalize()() `

Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.
` final https://developer.android.com/reference/java/lang/Class<?>` ` https://developer.android.com/reference/java/lang/Object#getClass()() `

Returns the runtime class of this `Object`.
` int` ` https://developer.android.com/reference/java/lang/Object#hashCode()() `

Returns a hash code value for the object.
` final void` ` https://developer.android.com/reference/java/lang/Object#notify()() `

Wakes up a single thread that is waiting on this object's monitor.
` final void` ` https://developer.android.com/reference/java/lang/Object#notifyAll()() `

Wakes up all threads that are waiting on this object's monitor.
` https://developer.android.com/reference/java/lang/String` ` https://developer.android.com/reference/java/lang/Object#toString()() `

Returns a string representation of the object.
` final void` ` https://developer.android.com/reference/java/lang/Object#wait(long,%20int)(long timeoutMillis, int nanos) `

Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*, or until a certain amount of real time has elapsed.
` final void` ` https://developer.android.com/reference/java/lang/Object#wait(long)(long timeoutMillis) `

Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*, or until a certain amount of real time has elapsed.
` final void` ` https://developer.android.com/reference/java/lang/Object#wait()() `

Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*.

## Public methods

### getDisplay

Added in [API level 19](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public Display getDisplay ()
```

Gets the virtual display.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/view/Display` | <br /> |

### getSurface

Added in [API level 20](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public Surface getSurface ()
```

Gets the surface that backs the virtual display.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/view/Surface` | <br /> |

### release

Added in [API level 19](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void release ()
```

Releases the virtual display and destroys its underlying surface.

All remaining windows on the virtual display will be forcibly removed as part of releasing the virtual display.

<br />

<br />

### resize

Added in [API level 21](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void resize (int width, 
                int height, 
                int densityDpi)
```

Asks the virtual display to resize.

This is really just a convenience to allow applications using virtual displays to adapt to changing conditions without having to tear down and recreate the display.

<br />

<br />

| Parameters ||
|---|---|
| `width` | `int` <br /> |
| `height` | `int` <br /> |
| `densityDpi` | `int` <br /> |

### setRotation

Added in [API level 36](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void setRotation (int rotation)
```

Sets the rotation of the virtual display.

<br />

| Parameters ||
|---|---|
| `rotation` | `int`: the new rotation of the display. May be one of `https://developer.android.com/reference/android/view/Surface#ROTATION_0`, `https://developer.android.com/reference/android/view/Surface#ROTATION_90`, `https://developer.android.com/reference/android/view/Surface#ROTATION_180`, `https://developer.android.com/reference/android/view/Surface#ROTATION_270`. Upon creation, the rotation of the virtual display is always `https://developer.android.com/reference/android/view/Surface#ROTATION_0`. Value is one of the following: - `https://developer.android.com/reference/android/view/Surface#ROTATION_0` - `https://developer.android.com/reference/android/view/Surface#ROTATION_90` - `https://developer.android.com/reference/android/view/Surface#ROTATION_180` - `https://developer.android.com/reference/android/view/Surface#ROTATION_270` |

### setSurface

Added in [API level 20](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void setSurface (Surface surface)
```

Sets the surface that backs the virtual display.

Detaching the surface that backs a virtual display has a similar effect to turning off the screen.

It is still the caller's responsibility to destroy the surface after it has been detached.

<br />

<br />

| Parameters ||
|---|---|
| `surface` | `Surface`: The surface to set, or null to detach the surface from the virtual display. <br /> |

### toString

Added in [API level 19](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public String toString ()
```

Returns a string representation of the object.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/lang/String` | a string representation of the object. <br /> |