This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.

Presentation Class
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Base class for presentations.
Java documentation for android.app.Presentation .
Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.
Constructors
Explicit interface implementations, extension methods, additional resources.
- React Native
Secondary Display Control via Android Presentation Class
In this blog, we will learn about Secondary Display Control via Android Presentation Class.
Well, the title line certainly deals with a lot of words that probably most of the developers are not aware of and frankly, even I was not aware of this beauty of Android until last month.
Before we start, let me just tell you a few practical use cases for what you can build after following along.
- POS Hardware Machines & their Dedicated Application –> Have you seen the agents at big retail centers using POS machines? There you can see what is being added to your cart at the same moment and the agent is processing your order. If you peek at agent’s screen the content will be a bit(or entirely) different.
- Presentation Apps –> Have you seen the applications where whole presentation(ppts, slides) are being controlled by some android device? If you peek at the Android device screen the slides are bit different (like with notes, descriptions, etc) but on the secondary screen (like a projector ) the presentation is entirely different.
After reading this blog you will also be able to build something similar.
Before we start talking about code let’s just clear what the words in the title are.
A display is referred to as a screen or area which can show the content.
As a result, an Android device can control any number of displays.
The main point to note is that the application’s code should be able to handle each display separately and these are in sync with the main display.
Main Display
This display refers to the actual screen provided by the manufacturer of the Android device.
Hence, this screen listens to all the user interactions, gestures and motions events.
As a result, this display is referred to as Main Display.
Secondary Display
This display refers to a secondary screen which is somehow (Bluetooth, wired connections, RFC) connected to your Android device.
By Default, this screen is not user interactive and hence it is called as Display and not Screen.
Presentation Class
A presentation is a special kind of dialog whose purpose is to present content on a secondary display. A Presentation is associated with the target Display at creation time and configures its context and resource configuration according to the display’s metrics. — developer.android.com
For Simple understanding, we need to extend this class to build a view to display on our Secondary Display.
With this understanding, now you can do anything you want on Secondary Display.
Now, in this blog, we will just be making a Welcome TextView on the Secondary Display.
- First, create a layout file that will be displayed on the secondary Display. For simplicity, name this file secondary_display.xml
- Now, we create a class that will extend the Presentation Class. Let’s name this class SecondaryDisplay.
- The Presentation class object we just created will have a default constructor and override the onCreate Method.
- The constructor will take Context & a display as arguments. This will be a reference to the secondary Display.
- The onCreate Method is similar to the Activity’s onCreate Method.
- Now to display this content, you just need to initialize the constructor of the SecondaryDisplay class and call the show() method. (just like we do for a dialog).
File Name –> secondary_display.xml
File Name –> SecondaryDisplay.java
With the help of lines below, you can set the Secondary Display Content.
With this last change, you have completed the task.
Now, just run your application on a device with Secondary Display and see the magic.
Keep coding and Keep Sharing 🙂
References –> https://developer.android.com/reference/android/app/Presentation
https://developer.android.com/reference/android/view/Display.html

Leave a Comment Cancel Reply
Your email address will not be published. Required fields are marked*
Save my name email and website in this browser for the next time I comment.
27 comments

You can easily try this option in any android device or emulators.
All you need to do is to enable the developer options.
Then in the developer options menu find the option “Simulate secondary displays”.
From the list that opens up , you can easily select the width option as per your need.

I am assuming that by control you want to listen to some of the events on the secondary display.
So, if that is all about majorly click listeners then you can add them as you add it to any of the views in your code in your secondary display class as well.
Though, I have not practically implemented any listeners for the secondary display.
But i guess, this should work fine.
Still, if you are looking for soemthing else, then feel free to type more over here.
Regards, Anchit

If you know the solution then please let me know.
Thanks, Sunil
I would need access to your code and then only i can help you out.

This seems to be pretty easy.
You can either create some method in your secondary display class and update the ui accordingly.
You can declare the components public and then access the same in the main activity.
Both will work.

I personally have not worked on automotive AVD.
As per me the connection to secondary screen in AVD will depend totally on how both of the screens are connected.
If the connection is physically wired, then you can also go with the points mentioned in the article.

To do this should I call presentation in all activities? Or can I call it from base activity?
i would recommend you to call in the base activity.
when you need to change the content on the secondary display just override the activity.

your welcome

while running this example on emulator. looking forward for your help.
For both points, please first check that the secondary display is fully simulated on your emulator.
If you are able to successfully simulate the dual-screen, then the article is good enough to work like a charm.

Please do share the same.

Your Welcome

also my project is library based where one base project and other modules are divided into libraries. so how to handle this kind of structure?
Yes, we can capture user input and interaction if the secondary hardware supports it.
Sorry, I can’t share samples right now but this is possible with simple logic.
For library-based project, i would recommend adding this functionality to the base project itself so that you can use it on the go in different libraries as per the use case.
Rest all can be done as per your project’s requirement.
We use cookies to personalize your experience. By continuing to visit this website you agree to our use of cookies. Learn more about privacy policy
We've bought a Shopware Extension which is a hybrid App, which we can now offer in the Google Play Store and the IOS App Store. I'am still impressed how fast and how sharp the support team leads us through every process of the App-Store clarification. Very fast and useful response.

Markus Walter
Founder, Das Apartment Living
Enquiry or Requirement
Message Sent!
If you have more details or questions, you can reply to the received confirmation email.

- Google Play Developer Console
- Android Developers Blog
- About Android
- Android.com
- Android Developers
- Android Open Source Project
- Get Started
- Building Blocks
- Get the SDK
- Google Services
- Google Play
- App Quality
- Open Distribution
- android.accessibilityservice
- android.accounts
- android.animation
- android.app
- android.app.admin
- android.app.backup
- android.appwidget
- android.bluetooth
- android.content
- android.content.pm
- android.content.res
- android.database
- android.database.sqlite
- android.drm
- android.gesture
- android.graphics
- android.graphics.drawable
- android.graphics.drawable.shapes
- android.hardware
- android.hardware.display
- android.hardware.input
- android.hardware.usb
- android.inputmethodservice
- android.location
- android.media
- android.media.audiofx
- android.media.effect
- android.mtp
- android.net
- android.net.http
- android.net.nsd
- android.net.rtp
- android.net.sip
- android.net.wifi
- android.net.wifi.p2p
- android.net.wifi.p2p.nsd
- android.nfc
- android.nfc.tech
- android.opengl
- android.os.storage
- android.preference
- android.provider
- android.renderscript
- android.sax
- android.security
- android.service.dreams
- android.service.textservice
- android.service.wallpaper
- android.speech
- android.speech.tts
- android.support.v13.app
- android.support.v4.accessibilityservice
- android.support.v4.app
- android.support.v4.content
- android.support.v4.content.pm
- android.support.v4.database
- android.support.v4.net
- android.support.v4.os
- android.support.v4.util
- android.support.v4.view
- android.support.v4.view.accessibility
- android.support.v4.widget
- android.telephony
- android.telephony.cdma
- android.telephony.gsm
- android.test
- android.test.mock
- android.test.suitebuilder
- android.text
- android.text.format
- android.text.method
- android.text.style
- android.text.util
- android.util
- android.view
- android.view.accessibility
- android.view.animation
- android.view.inputmethod
- android.view.textservice
- android.webkit
- android.widget
- dalvik.bytecode
- dalvik.system
- java.awt.font
- java.lang.annotation
- java.lang.ref
- java.lang.reflect
- java.nio.channels
- java.nio.channels.spi
- java.nio.charset
- java.nio.charset.spi
- java.security
- java.security.acl
- java.security.cert
- java.security.interfaces
- java.security.spec
- java.util.concurrent
- java.util.concurrent.atomic
- java.util.concurrent.locks
- java.util.jar
- java.util.logging
- java.util.prefs
- java.util.regex
- java.util.zip
- javax.crypto
- javax.crypto.interfaces
- javax.crypto.spec
- javax.microedition.khronos.egl
- javax.microedition.khronos.opengles
- javax.net.ssl
- javax.security.auth
- javax.security.auth.callback
- javax.security.auth.login
- javax.security.auth.x500
- javax.security.cert
- javax.xml.datatype
- javax.xml.namespace
- javax.xml.parsers
- javax.xml.transform
- javax.xml.transform.dom
- javax.xml.transform.sax
- javax.xml.transform.stream
- javax.xml.validation
- javax.xml.xpath
- junit.framework
- junit.runner
- org.apache.http
- org.apache.http.auth
- org.apache.http.auth.params
- org.apache.http.client
- org.apache.http.client.entity
- org.apache.http.client.methods
- org.apache.http.client.params
- org.apache.http.client.protocol
- org.apache.http.client.utils
- org.apache.http.conn
- org.apache.http.conn.params
- org.apache.http.conn.routing
- org.apache.http.conn.scheme
- org.apache.http.conn.ssl
- org.apache.http.conn.util
- org.apache.http.cookie
- org.apache.http.cookie.params
- org.apache.http.entity
- org.apache.http.impl
- org.apache.http.impl.auth
- org.apache.http.impl.client
- org.apache.http.impl.conn
- org.apache.http.impl.conn.tsccm
- org.apache.http.impl.cookie
- org.apache.http.impl.entity
- org.apache.http.impl.io
- org.apache.http.io
- org.apache.http.message
- org.apache.http.params
- org.apache.http.protocol
- org.apache.http.util
- org.w3c.dom
- org.w3c.dom.ls
- org.xml.sax
- org.xml.sax.ext
- org.xml.sax.helpers
- org.xmlpull.v1
- org.xmlpull.v1.sax2
- ActionBar.OnMenuVisibilityListener
- ActionBar.OnNavigationListener
- ActionBar.TabListener
- Application.ActivityLifecycleCallbacks
- DatePickerDialog.OnDateSetListener
- FragmentBreadCrumbs.OnBreadCrumbClickListener
- FragmentManager.BackStackEntry
- FragmentManager.OnBackStackChangedListener
- KeyguardManager.OnKeyguardExitResult
- LoaderManager.LoaderCallbacks
- PendingIntent.OnFinished
- SearchManager.OnCancelListener
- SearchManager.OnDismissListener
- TimePickerDialog.OnTimeSetListener
- ActionBar.LayoutParams
- ActionBar.Tab
- ActivityGroup
- ActivityManager
- ActivityManager.MemoryInfo
- ActivityManager.ProcessErrorStateInfo
- ActivityManager.RecentTaskInfo
- ActivityManager.RunningAppProcessInfo
- ActivityManager.RunningServiceInfo
- ActivityManager.RunningTaskInfo
- ActivityOptions
- AlarmManager
- AlertDialog
- AlertDialog.Builder
- AliasActivity
- Application
- ApplicationErrorReport
- ApplicationErrorReport.AnrInfo
- ApplicationErrorReport.BatteryInfo
- ApplicationErrorReport.CrashInfo
- ApplicationErrorReport.RunningServiceInfo
- DatePickerDialog
- DialogFragment
- DownloadManager
- DownloadManager.Query
- DownloadManager.Request
- ExpandableListActivity
- Fragment.SavedState
- FragmentBreadCrumbs
- FragmentManager
- FragmentTransaction
- Instrumentation
- Instrumentation.ActivityMonitor
- Instrumentation.ActivityResult
- IntentService
- KeyguardManager
- KeyguardManager.KeyguardLock
- LauncherActivity
- LauncherActivity.IconResizer
- LauncherActivity.ListItem
- ListActivity
- ListFragment
- LoaderManager
- LocalActivityManager
- MediaRouteActionProvider
- MediaRouteButton
- NativeActivity
- Notification
- Notification.BigPictureStyle
- Notification.BigTextStyle
- Notification.Builder
- Notification.InboxStyle
- Notification.Style
- NotificationManager
- PendingIntent
Presentation
- ProgressDialog
- SearchableInfo
- SearchManager
- TabActivity
- TaskStackBuilder
- TimePickerDialog
- UiModeManager
- WallpaperInfo
- WallpaperManager
- Fragment.InstantiationException
- PendingIntent.CanceledException
Class Overview
A presentation is a special kind of dialog whose purpose is to present content on a secondary display. A Presentation is associated with the target Display at creation time and configures its context and resource configuration according to the display's metrics.
Notably, the Context of a presentation is different from the context of its containing Activity . It is important to inflate the layout of a presentation and load other resources using the presentation's own context to ensure that assets of the correct size and density for the target display are loaded.
A presentation is automatically canceled (see cancel() ) when the display to which it is attached is removed. An activity should take care of pausing and resuming whatever content is playing within the presentation whenever the activity itself is paused or resumed.
Choosing a presentation display
Before showing a Presentation it's important to choose the Display on which it will appear. Choosing a presentation display is sometimes difficult because there may be multiple displays attached. Rather than trying to guess which display is best, an application should let the system choose a suitable presentation display.
There are two main ways to choose a Display .
Using the media router to choose a presentation display
The easiest way to choose a presentation display is to use the MediaRouter API. The media router service keeps track of which audio and video routes are available on the system. The media router sends notifications whenever routes are selected or unselected or when the preferred presentation display of a route changes. So an application can simply watch for these notifications and show or dismiss a presentation on the preferred presentation display automatically.
The preferred presentation display is the display that the media router recommends that the application should use if it wants to show content on the secondary display. Sometimes there may not be a preferred presentation display in which case the application should show its content locally without using a presentation.
Here's how to use the media router to create and show a presentation on the preferred presentation display using getPresentationDisplay() .
The following sample code from ApiDemos demonstrates how to use the media router to automatically switch between showing content in the main activity and showing the content in a presentation when a presentation display is available.
Using the display manager to choose a presentation display
Another way to choose a presentation display is to use the DisplayManager API directly. The display manager service provides functions to enumerate and describe all displays that are attached to the system including displays that may be used for presentations.
The display manager keeps track of all displays in the system. However, not all displays are appropriate for showing presentations. For example, if an activity attempted to show a presentation on the main display it might obscure its own content (it's like opening a dialog on top of your activity).
Here's how to identify suitable displays for showing presentations using getDisplays(String) and the DISPLAY_CATEGORY_PRESENTATION category.
The following sample code from ApiDemos demonstrates how to use the display manager to enumerate displays and show content on multiple presentation displays simultaneously.
- for information on about live video routes and how to obtain the preferred presentation display for the current media route.
- for information on how to enumerate displays and receive notifications when displays are added or removed.

Public Constructors
Public presentation ( context outercontext, display display).
Creates a new presentation that is attached to the specified display using the default theme.
public Presentation ( Context outerContext, Display display, int theme)
Creates a new presentation that is attached to the specified display using the optionally specified theme.
Public Methods
Public display getdisplay ().
Gets the Display that this presentation appears on.
- The display.
public Resources getResources ()
Gets the Resources that should be used to inflate the layout of this presentation. This resources object has been configured according to the metrics of the display that the presentation appears on.
- The presentation resources object.
public void onDisplayChanged ()
Called by the system when the properties of the Display to which the presentation is attached have changed. If the display metrics have changed (for example, if the display has been resized or rotated), then the system automatically calls cancel() to dismiss the presentation.
- getDisplay()
public void onDisplayRemoved ()
Called by the system when the Display to which the presentation is attached has been removed. The system automatically calls cancel() to dismiss the presentation after sending this event.
public void show ()
Inherited from show() . Will throw WindowManager.InvalidDisplayException if the specified secondary Display can't be found.
Protected Methods
Protected void onstart ().
Called when the dialog is starting.
protected void onStop ()
Called to tell you that you're stopping.
About Android | Legal | Support
- Stack Overflow Public questions & answers
- Stack Overflow for Teams Where developers & technologists share private knowledge with coworkers
- Talent Build your employer brand
- Advertising Reach developers & technologists worldwide
- About the company
Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Android Presentation Class - How to make changes on the Presentation View dynamically
My presentation is working finally. I have one main activity for my first screen and one Presentation for my second Screen. My problem is, that I can't change the content on my presentation view.
Why can't I change a TextView after the presentation is shown on the second screen? Calling the method changeText("Test123") in the MainActivity crashes my app.
- presentation

- Use LogCat to examine the Java stack trace associated with your crash. – CommonsWare Jul 2, 2013 at 18:22
- Hi! I can't use LogCat because my USB port is used to connect the second screen with HDMI. – user1972807 Jul 2, 2013 at 23:10
- edit: ok, there are some Apps for LogCat. I will test it tomorrow. Thanks! – user1972807 Jul 2, 2013 at 23:16
- Then disconnect your MHL(?) cable after the crash, plug it into USB on your development machine, and then examine LogCat. Or, you might be able to get adb to work over USB, see tech.leolink.net/2012/11/use-adb-wifi-without-rooting-for.html . The apps you cite won't work, as you cannot view LogCat messages from other processes in an app on Android 4.1+. – CommonsWare Jul 2, 2013 at 23:17
2 Answers 2
Well, I looked in the LogCat. The exception was:
The code in my MainActivity runs on another thread. To do UI work from here I need to use runOnUiThread . This solution I found in this answer.
My changeText methode looks like this now:
Thanks for the help! Now I know how to use LogCat for things like that.
You got this issue because the context of presentation is different from that of the containing Activity:
A Presentation is associated with the target Display at creation time and configures its context and resource configuration according to the display's metrics. Notably, the Context of a presentation is different from the context of its containing Activity. It is important to inflate the layout of a presentation and load other resources using the presentation's own context to ensure that assets of the correct size and density for the target display are loaded.
Hope this will justify your mentioned solution as well.
Your Answer
Sign up or log in, post as a guest.
Required, but never shown
By clicking “Post Your Answer”, you agree to our terms of service , privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged android screen presentation or ask your own question .
- The Overflow Blog
- The nature of simulating nature: A Q&A with IBM Quantum researcher Dr. Jamie...
- Five Stack Exchange sites turned ten years-old this quarter!
- Featured on Meta
- We've added a "Necessary cookies only" option to the cookie consent popup
- Launching the CI/CD and R Collectives and community editing features for...
- The [amazon] tag is being burninated
- Temporary policy: ChatGPT is banned
- Staging Ground Beta 1 Recap, and Reviewers needed for Beta 2
Hot Network Questions
- Move duplicated folder name up one level
- My code is GPL licensed, can I issue a license to have my code be distributed in a specific MIT licensed project?
- Google maps for Space exploration
- Should I put my dog down to help the homeless?
- Wildly different answers replicating a GEE model from SPSS
- Resistance depending on voltage - the chicken and the egg?
- Does the attacker need to be on the same network to carry out a deauthentication attack?
- How can I set a face/style in emacs for a quote in org mode?
- A Swiss watch company seized my watch, saying it was stolen. I bought it 10 years ago, is that legal?
- What are the Stargate dial home device symbols used to dial Earth from Atlantis?
- Disconnect between goals and daily tasks...Is it me, or the industry?
- In England, why are some high schools called hospitals?
- Why did Windows 3.0 fail in Japan?
- Separating layers based on labels
- Is there any room for negotiation on my PhD program stipend offers?
- Forced to pay a customs fee for importing a used wedding dress into the Netherlands. Is there a way to avoid paying?
- What is "ぷれせんとふぉーゆーさん" exactly referring to?
- What is the name of the color used by the SBB (Swiss Federal Railway) in the 1920s to paint their locomotive?
- Truth behind Samuelson's statement against elasticities
- Question regarding pull-up and battery charger charging current
- Are there any sources with high-confidence state vectors for GRAIL-A?
- What do we really know about lotteries?
- Max-heap implementation in C
- Why do academics stay as adjuncts for years rather than move around?
Your privacy
By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy .
- android.app.ActionBar
- android.app.ActionBar.DisplayOptions
- android.app.ActionBar.LayoutParams
- android.app.ActionBar.NavigationMode
- android.app.ActionBar.OnMenuVisibilityListener
- android.app.ActionBar.OnNavigationListener
- android.app.ActionBar.Tab
- android.app.ActionBar.TabListener
- android.app.Activity
- android.app.Activity.TranslucentConversionListener
- android.app.ActivityGroup
- android.app.ActivityManager
- android.app.ActivityManager.AppTask
- android.app.ActivityManager.BugreportMode
- android.app.ActivityManager.MemoryInfo
- android.app.ActivityManager.MoveTaskFlags
- android.app.ActivityManager.OnUidImportanceListener
- android.app.ActivityManager.ProcessErrorStateInfo
- android.app.ActivityManager.RecentTaskInfo
- android.app.ActivityManager.RunningAppProcessInfo
- android.app.ActivityManager.RunningAppProcessInfo.Importance
- android.app.ActivityManager.RunningServiceInfo
- android.app.ActivityManager.RunningTaskInfo
- android.app.ActivityManager.StackInfo
- android.app.ActivityManager.TaskDescription
- android.app.ActivityManager.TaskSnapshot
- android.app.ActivityManagerInternal
- android.app.ActivityManagerNative
- android.app.ActivityOptions
- android.app.ActivityOptions.OnAnimationFinishedListener
- android.app.ActivityOptions.OnAnimationStartedListener
- android.app.ActivityTaskManager
- android.app.ActivityThread
- android.app.ActivityThread.ActivityClientRecord
- android.app.ActivityView
- android.app.ActivityView.StateCallback
- android.app.AlarmManager
- android.app.AlarmManager.AlarmClockInfo
- android.app.AlarmManager.AlarmType
- android.app.AlarmManager.OnAlarmListener
- android.app.AlertDialog
- android.app.AlertDialog.Builder
- android.app.AliasActivity
- android.app.AppComponentFactory
- android.app.AppDetailsActivity
- android.app.AppGlobals
- android.app.AppOpsManager
- android.app.AppOpsManager.DataBucketKey
- android.app.AppOpsManager.HistoricalMode
- android.app.AppOpsManager.HistoricalOp
- android.app.AppOpsManager.HistoricalOps
- android.app.AppOpsManager.HistoricalOpsRequest
- android.app.AppOpsManager.HistoricalOpsVisitor
- android.app.AppOpsManager.HistoricalPackageOps
- android.app.AppOpsManager.HistoricalUidOps
- android.app.AppOpsManager.Mode
- android.app.AppOpsManager.OnOpActiveChangedListener
- android.app.AppOpsManager.OnOpChangedInternalListener
- android.app.AppOpsManager.OnOpChangedListener
- android.app.AppOpsManager.OnOpNotedListener
- android.app.AppOpsManager.OpEntry
- android.app.AppOpsManager.OpFlags
- android.app.AppOpsManager.PackageOps
- android.app.AppOpsManager.UidState
- android.app.AppOpsManagerInternal
- android.app.AppOpsManagerInternal.CheckOpsDelegate
- android.app.Application
- android.app.Application.ActivityLifecycleCallbacks
- android.app.Application.OnProvideAssistDataListener
- android.app.ApplicationErrorReport
- android.app.ApplicationErrorReport.AnrInfo
- android.app.ApplicationErrorReport.BatteryInfo
- android.app.ApplicationErrorReport.CrashInfo
- android.app.ApplicationErrorReport.ParcelableCrashInfo
- android.app.ApplicationLoaders
- android.app.ApplicationPackageManager
- android.app.ApplicationPackageManager.OnPermissionsChangeListenerDelegate
- android.app.ApplicationThreadConstants
- android.app.AuthenticationRequiredException
- android.app.AutomaticZenRule
- android.app.BroadcastOptions
- android.app.ClientTransactionHandler
- android.app.ContentProviderHolder
- android.app.DatePickerDialog
- android.app.DatePickerDialog.OnDateSetListener
- android.app.Dialog
- android.app.DialogFragment
- android.app.DirectAction
- android.app.DownloadManager
- android.app.DownloadManager.Query
- android.app.DownloadManager.Request
- android.app.ExpandableListActivity
- android.app.Fragment
- android.app.Fragment.InstantiationException
- android.app.Fragment.SavedState
- android.app.FragmentBreadCrumbs
- android.app.FragmentBreadCrumbs.OnBreadCrumbClickListener
- android.app.FragmentContainer
- android.app.FragmentController
- android.app.FragmentHostCallback
- android.app.FragmentManager
- android.app.FragmentManager.BackStackEntry
- android.app.FragmentManager.FragmentLifecycleCallbacks
- android.app.FragmentManager.OnBackStackChangedListener
- android.app.FragmentManagerNonConfig
- android.app.FragmentTransaction
- android.app.FragmentTransaction.Transit
- android.app.Fragment_Delegate
- android.app.GrantedUriPermission
- android.app.InstantAppResolverService
- android.app.InstantAppResolverService.InstantAppResolutionCallback
- android.app.Instrumentation
- android.app.Instrumentation.ActivityMonitor
- android.app.Instrumentation.ActivityResult
- android.app.Instrumentation.UiAutomationFlags
- android.app.IntentService
- android.app.JobSchedulerImpl
- android.app.KeyguardManager
- android.app.KeyguardManager.KeyguardDismissCallback
- android.app.KeyguardManager.KeyguardLock
- android.app.KeyguardManager.OnKeyguardExitResult
- android.app.LauncherActivity
- android.app.LauncherActivity.IconResizer
- android.app.LauncherActivity.ListItem
- android.app.ListActivity
- android.app.ListFragment
- android.app.LoadedApk
- android.app.LoaderManager
- android.app.LoaderManager.LoaderCallbacks
- android.app.LocalActivityManager
- android.app.MediaRouteActionProvider
- android.app.MediaRouteButton
- android.app.NativeActivity
- android.app.Notification
- android.app.Notification.Action
- android.app.Notification.Action.SemanticAction
- android.app.Notification.BigPictureStyle
- android.app.Notification.BigTextStyle
- android.app.Notification.BubbleMetadata
- android.app.Notification.CarExtender
- android.app.Notification.CarExtender.UnreadConversation
- android.app.Notification.DecoratedCustomViewStyle
- android.app.Notification.DecoratedMediaCustomViewStyle
- android.app.Notification.Extender
- android.app.Notification.GroupAlertBehavior
- android.app.Notification.InboxStyle
- android.app.Notification.MediaStyle
- android.app.Notification.MessagingStyle
- android.app.Notification.MessagingStyle.Message
- android.app.Notification.Priority
- android.app.Notification.Style
- android.app.Notification.TvExtender
- android.app.Notification.Visibility
- android.app.Notification.WearableExtender
- android.app.NotificationChannel
- android.app.NotificationChannelGroup
- android.app.NotificationManager
- android.app.NotificationManager.InterruptionFilter
- android.app.NotificationManager.Policy
- android.app.OnActivityPausedListener
- android.app.PackageDeleteObserver
- android.app.PackageInstallObserver
- android.app.PendingIntent
- android.app.PendingIntent.CancelListener
- android.app.PendingIntent.CanceledException
- android.app.PendingIntent.Flags
- android.app.PendingIntent.OnFinished
- android.app.PendingIntent.OnMarshaledListener
- android.app.PendingIntentPerfTest
- android.app.Person
- android.app.PictureInPictureArgs
- android.app.PictureInPictureParams
- android.app.Presentation
- android.app.ProcessMemoryState
- android.app.ProfilerInfo
- android.app.ProgressDialog
- android.app.QueuedWork
- android.app.RecoverableSecurityException
- android.app.RecoverableSecurityException.LocalDialog
- android.app.RemoteAction
- android.app.RemoteInput
- android.app.RemoteInput.EditChoicesBeforeSending
- android.app.RemoteInput.Source
- android.app.ResourcesManager
- android.app.ResourcesPerfTest
- android.app.ResourcesThemePerfTest
- android.app.ResultInfo
- android.app.SearchDialog
- android.app.SearchDialog.SearchBar
- android.app.SearchManager
- android.app.SearchManager.OnCancelListener
- android.app.SearchManager.OnDismissListener
- android.app.SearchableInfo
- android.app.SearchableInfo.ActionKeyInfo
- android.app.Service
- android.app.Service.StartArgFlags
- android.app.Service.StartResult
- android.app.Service.StopForegroundFlags
- android.app.ServiceStartArgs
- android.app.SharedElementCallback
- android.app.SharedElementCallback.OnSharedElementsReadyListener
- android.app.StatsManager
- android.app.StatsManager.StatsUnavailableException
- android.app.StatusBarManager
- android.app.StatusBarManager.Disable2Flags
- android.app.StatusBarManager.DisableFlags
- android.app.StatusBarManager.DisableInfo
- android.app.StatusBarManager.WindowType
- android.app.StatusBarManager.WindowVisibleState
- android.app.SynchronousUserSwitchObserver
- android.app.SystemServiceRegistry_Accessor
- android.app.TabActivity
- android.app.TaskInfo
- android.app.TaskStackBuilder
- android.app.TaskStackListener
- android.app.TimePickerDialog
- android.app.TimePickerDialog.OnTimeSetListener
- android.app.UiAutomation
- android.app.UiAutomation.AccessibilityEventFilter
- android.app.UiAutomation.OnAccessibilityEventListener
- android.app.UiAutomationConnection
- android.app.UiAutomationConnection.Repeater
- android.app.UiModeManager
- android.app.UiModeManager.NightMode
- android.app.UriGrantsManager
- android.app.UserSwitchObserver
- android.app.VoiceInteractor
- android.app.VoiceInteractor.AbortVoiceRequest
- android.app.VoiceInteractor.CommandRequest
- android.app.VoiceInteractor.CompleteVoiceRequest
- android.app.VoiceInteractor.ConfirmationRequest
- android.app.VoiceInteractor.PickOptionRequest
- android.app.VoiceInteractor.PickOptionRequest.Option
- android.app.VoiceInteractor.Prompt
- android.app.Vr2dDisplayProperties
- android.app.Vr2dDisplayProperties.Vr2dDisplayFlag
- android.app.VrManager
- android.app.VrStateCallback
- android.app.WaitResult
- android.app.WaitResult.LaunchState
- android.app.WallpaperColors
- android.app.WallpaperInfo
- android.app.WallpaperManager
- android.app.WallpaperManager.OnColorsChangedListener
- android.app.WallpaperManager.SetWallpaperFlags
- android.app.WindowConfiguration
- android.app.WindowConfiguration.ActivityType
- android.app.WindowConfiguration.WindowConfig
- android.app.WindowConfiguration.WindowingMode
- android.app.ZygotePreload

Level Up Coding

Member-only
A Guide to Second Screen Apps in Android
Using presentation class to display second screen in android.
Using a second screen in your Android app can be a great way to enhance the user experience and provide additional information or functionality. One way to accomplish this is by using the Presentation class in Kotlin.
The Presentation class is a part of the Android SDK that allows you to create a separate window for displaying content on a secondary display. This can be useful for showing additional information, such as a video or slide presentation, while the main screen continues to display the primary app content.
To use the Presentation class, you will first need to create a new class that extends Presentation. In this class, you can define the layout and functionality for the second screen. For example, you might include a video player, a list of items, or a web view.
Here is an example of how you might create a basic Presentation class in Kotlin:
Once you have defined your Presentation class, you can create an instance of it in your main activity and display it on the secondary screen. To do this, you will need to get the Display object for the secondary screen and pass it to the Presentation constructor.
You can also add other functionalities like click events, data updates, etc.
In order to get a secondary display in an Android app, you will need to use the DisplayManager class. The DisplayManager class allows you to access information about the available displays on the device, including the primary display and any connected secondary displays.
Here is an example of how you might use the DisplayManager class to get a secondary display in an Android app:
In this example, the code first gets a reference to the DisplayManager service using the getSystemService() method. It then retrieves an array of all the available displays using the displays property. The code then loops through the displays array, checking the displayId property of each display. If the displayId is not equal to Display.DEFAULT_DISPLAY, then it is a secondary display.
It’s important to check if there is any secondary display available before trying to use it, so you can handle the case of no secondary display available and avoid app crashes.
In this way, you can use the Presentation class to create a second screen in your Android app using Kotlin. With this, you can provide additional information or functionality to your users while they continue to use the main screen of your app.
It is important to note that the Presentation class is only available on Android devices that support a secondary screen. So, it’s important to check for the availability of a secondary screen before trying to use the Presentation class, to avoid app crashes.
This is a basic example, but you can customize it as per your requirements and make it more interactive and user-friendly.
I hope this helps you to understand how to use the Presentation class to create a second screen in your Android app using Kotlin.
If you liked this story and want tao read thousands of stories like this on Medium from me and various top writers, you can become a Medium member for as little as 5$ a month . If you’d like to support my writing, use my referral link , and I will get a portion of your membership without any extra cost to you.
More from Level Up Coding
Coding tutorials and news. The developer homepage gitconnected.com && skilled.dev && levelup.dev
About Help Terms Privacy
Get the Medium app

Dharmesh Basapati
App Developer & Content Freak | Loves Coding, Writing & Branding | https://linktr.ee/dharmeshbasapati
Text to speech
How to use Presentation in android.app
Best java code snippets using android.app . presentation (showing top 20 results out of 315).
- No suggested jump to results
- Notifications
CWAC Presentation: Second Screen Support Simplified
commonsguy/cwac-presentation
Name already in use.
Use Git or checkout with SVN using the web URL.
Work fast with our official CLI. Learn more .
- Open with GitHub Desktop
- Download ZIP
Sign In Required
Please sign in to use Codespaces.
Launching GitHub Desktop
If nothing happens, download GitHub Desktop and try again.
Launching Xcode
If nothing happens, download Xcode and try again.
Launching Visual Studio Code
Your codespace will open once ready.
There was a problem preparing your codespace, please try again.
Latest commit
Readme.markdown, cwac-presentation: second screens supported succinctly.
UPDATE 2021-05-08 : This project is discontinued. This repository will be removed from public access on or after 1 December 2021.
This project offers a series of classes that wrap around Presentation and DisplayManager :
PresentationHelper consolidates basic DisplayManager handling, with a listener to inform you when to show or remove your Presentation
PresentationFragment extends DialogFragment and adds a bit of extra logic to allow it to handle a Presentation rather than a simple Dialog
WebPresentationFragment simply extends PresentationFragment and displays a WebView in the Presentation
MirroringFragment , MirroringWebViewFragment , and MirrorPresentationFragment leverage the mirroring logic from the CWAC-Layouts project to help you display a Presentation based upon mirrored content from the main screen
PresentationService , for showing content on an external display from the background, even if your primary UI is destroyed or otherwise not in the foreground
Installation
This project is available as an artifact for use with Gradle.
There are two versions of this library, for AndroidX and for the older Android Support Library.
If you cannot use SSL, use http://repo.commonsware.com for the repository URL.
Android Support Library
Usage: presentationhelper.
PresentationHelper is designed to be used by an Activity that wishes to display a Presentation when a suitable Display is attached, and stop displaying the Presentation when any prior such Display is detached.
To do this:
Create an instance of PresentationHelper , probably in onCreate() of the activity. You will need to supply a Context (probably this ) and something that implements the PresentationHelper.Listener interface.
Forward the onPause() and onResume() events to the PresentationHelper by calling the same-named methods on the helper.
Implement the showPreso() method on your Listener . This receives a Display object, and you are now able to display a Presentation on that Display .
Implement the clearPreso() method on your Listener . At this point, you should stop displaying any prior Presentation , if there was one. You are passed a boolean value, true indicating that the activity is going away, false indicating that we merely lost our Display . You can use this value to perhaps optimize dealing with Display changes, without destroying all the data.
You can call disable() and enable() on the PresentationHelper . Calling disable() stops the custom content and reverts the device to normal screen mirroring mode. Calling enable() reverts a previous disable() call.
Usage: PresentationFragment
PresentationFragment is a thin veneer over DialogFragment to allow it to work with Presentation objects (which themselves inherit from Dialog ). This allows you to define the content for a Presentation in the form of a fragment. And, like DialogFragment , you can elect to either use it for a Presentation (via a call to show() ) or use it as an ordinary Fragment in the rest of your UI (via a FragmentTransaction ). This can help you to work both in dual-screen and single-screen scenarios.
Your PresentationFragment subclass should override onCreateView() to define the contents of the Presentation (or what will be shown in the Fragment when used as a regular fragment). The only significant change over any other Fragment is that you should use getContext() , instead of getActivity() , for any resources you create, such as inflating a layout. This ensures that you get the right Context for the situation, such as the Context associated with a secondary screen when used for a Presentation .
However, when creating the PresentationFragment , you also need to call setDisplay() , to provide the Display object for use when the fragment is shown as a Presentation . If you are not using it for a Presentation in the current context, this call is not required. A typical approach for handling setDisplay() is to use a factory method:
Beyond this, PresentationFragment is a fairly ordinary Fragment .
If you wish to display this fragment in a Presentation , call show() on the PresentationFragment , supplying your FragmentManager and a tag to use for the fragment itself. To get rid of the Presentation , call dismiss() on the PresentationFragment .
NOTE : In the AndroidX artifacts ( presentation.x ), PresentationFragment extends androidx.fragment.app.Fragment . In the legacy artifact ( presentation ), PresentationFragment extends android.app.Fragment .
Usage: WebPresentationFragment
WebPresentationFragment is simply a mash-up of PresentationFragment and WebViewFragment , to allow a WebView to be displayed in a Presentation . You use it just like WebViewFragment , except for the need to call setDisplay() (per the PresentationFragment instructions above). So, for example, getWebView() returns the WebView hosted by the WebPresentationFragment .
NOTE : In the AndroidX artifacts ( presentation.x ), WebPresentationFragment inherits from androidx.fragment.app.Fragment . In the legacy artifact ( presentation ), WebPresentationFragment inherits from android.app.Fragment .
Usage: Mirroring Presentation Classes
There are three classes that take advantage of the mirroring support included in the CWAC-Layouts project .
MirroringFragment works much like a regular Fragment . However, instead of overriding onCreateView() , you override onCreateMirroredContent() . onCreateMirroredContent() takes the same parameters as does onCreateView() , and your job is the same: create the content to be displayed by the fragment. The difference is that your returned View will be wrapped in a MirroringFrameLayout .
MirroringWebViewFragment is a mash-up of MirroringFragment and WebViewFragment , to allow a WebView to be mirrored. Use getWebView() to retrieve the WebView hosted by this fragment.
MirrorPresentationFragment is a PresentationFragment designed to mirror the contents of a MirroringFragment . To use this, create an instance using the newInstance() factory method, taking a Context and the desired Display as parameters. Then, call setMirror() on your MirroringFragment , supplying the MirrorPresentationFragment . From there, you can show() and dismiss() the MirrorPresentationFragment as you would any other PresentationFragment . By having the MirroringFragment on the main screen, and having the MirrorPresentationFragment on an external display, whatever the user manipulates on the screen is rendered to the external display, ideal for presentation settings (e.g., conferences).
Note that MirroringFragment suffers the same limitations as does MirroringFrameLayout , in that it will work with fairly ordinary View s, plus WebView , but not SurfaceView or things that use SurfaceView (e.g., VideoView , Maps V2 maps).
NOTE : In the AndroidX artifacts ( presentation.x ), these fragments inherit from androidx.fragment.app.Fragment . In the legacy artifact ( presentation ), these fragments inherit from android.app.Fragment .
Usage: PresentationService
PresentationService is an abstract base class for you to extend, where PresentationService handles showing your content on an external display, and you simply manage that content.
In your PresentationService subclass, you will need to implement two methods:
getThemeId() , which returns the ID of the style resource that you want to use for content being shown on the external display.
buildPresoView() , which returns the View that represents the content to show on the external display. Note that since this is a Service , not an Activity , you cannot use fragments, only views. buildPresoView() is passed a Context and a LayoutInflater for your use to set up the content to be displayed.
You may optionally override the standard lifecycle methods (though please chain to the superclass!) and buildLayoutParams() , which returns a WindowManager.LayoutParams describing how your View should be applied to the external display. The default implementation of buildLayoutParams() is probably adequate for your needs.
You may also optionally override the showPreso() and clearPreso() methods defined by PresentationHelper.Listener , though, once again, please chain to the superclass implementations.
You may also optionally override getWindowType() . This should return the window type int to be used for the "window" we are going to use for the external display. The stock implementation of getWindowType() uses TYPE_TOAST prior to Android 7.1 and TYPE_SYSTEM_ALERT on Android 7.1+. If you are using Cast Remote Display, you may need to override this method and return TYPE_PRIVATE_PRESENTATION (untested).
Then, all you need to do is to arrange to start and stop the service as needed. Once started, the service will automatically call buildPresoView() and show the content, once an external display is detected.
If things that the user does in your UI should affect the behavior of the service and its content, use a message bus implementation, such as LocalBroadcastManager . Your PresentationService can receive bus messages and update the View accordingly. Note that there is no present means to replace the View , so you may wish to have buildPresoView() return a FrameLayout or something else whose contents you can replace in toto if needed.
Note that it is safe to call startService() on the service multiple times, if you do not know whether the service is already running and need to ensure that it is running now.
Note that using this on Android 7.1+, where a TYPE_SYSTEM_ALERT window is used, requires the user to go into Settings and allow your app to draw over other apps.
On Android 8.0+, please use multi-display instead of PresentationService . However, PresentationService will work on Android 8.0+ if needed.
You can browse the JavaDocs for the latest release .
Dependencies
This project depends on Android 4.2 and higher (API Level 17) to actually do its work.
This project also depends upon the CWAC-Layouts project .
The AndroidX edition of this artifact ( presentation.x ) depends upon androidx.fragment:fragment .
This is version v0.6.1 of this artifact, meaning it is coming along nicely.
Note that the Android Support library edition of this arifact ( presentation ) remains at 0.5.3. Outside of critical bug fixes, no further work is planned for this version.
In the demo/ sub-project you will find a sample project demonstrating the use of the aforementioned classes, with the exception of PresentationService . There is a separate demoService/ sub-project with a sample implementation of PresentationService .
Additional Documentation
The Busy Coder's Guide to Android Development contains a chapter dedicated to the Presentation API. This chapter walks through a few sample apps that use classes from this library. Another chapter in the book examines a somewhat larger app that supports output on TVs, etc. by a variety of means (e.g., direct-to-TV devices like Android TV and Fire TV) including Presentation and this library's classes.
The code in this project is licensed under the Apache Software License 2.0, per the terms of the included LICENSE file.
If you have questions regarding the use of this code, please post a question on Stack Overflow tagged with commonsware-cwac and android after searching to see if there already is an answer . Be sure to indicate what CWAC module you are having issues with, and be sure to include source code and stack traces if you are encountering crashes.
If you have encountered what is clearly a bug, or if you have a feature request, please post an issue . The contribution guidelines provide some suggestions for how to create a bug report that will get the problem fixed the fastest.
You are also welcome to join the CommonsWare Community and post questions and ideas to the CWAC category .
Do not ask for help via social media.
Also, if you plan on hacking on the code with an eye for contributing something back, please open an issue that we can use for discussing implementation details. Just lobbing a pull request over the fence may work, but it may not. Again, the contribution guidelines provide a bit of guidance here.
Release Notes
- v0.6.1: fixed less-than bug
- v0.6.0: migrated to AndroidX and started a new artifact ( presentation.x )
- v0.5.3: fixed less-than bug
- v0.5.2: added support for Android 8.0+
- v0.5.1: updated to new Gradle, Android Plugin for Gradle, etc.
- v0.5.0: better PresentationService support for Android 7.1+, demo bug fixes
- v0.4.6: JavaDocs, sources included in repo; source tree reorg; build files update
- v0.4.5: got PresentationService working again on Android 5.1
- v0.4.4: updated for Android Studio 1.0 and new AAR publishing system
- v0.4.3: removed SYSTEM_ALERT_WINDOW permission requirement
- v0.4.2: updated Gradle, fixed manifest for merging, added cwac- prefix to JAR
- v0.4.1: tweak for v0.4.0 of CWAC-Layouts
- v0.4.0: added PresentationService
- v0.3.0: migrated to Gradle
- v0.2.0: handle API level diffs, support enable/disable of PresentationHelper
- v0.1.0: initial release
Who Made This?
- Java 100.0%

Google Slides
About this app
Data safety.
Ratings and reviews
- Flag inappropriate
- Show review history
What's new
Developer contact, similar apps.
More by Google LLC

IMAGES
VIDEO
COMMENTS
Shortage of sleep, psychological problems, vehicle breakdowns and lack of responsibility are some reasons why students arrive late to class. Teachers who don’t enforce tardy policies can also negatively affect any student desire to be on ti...
Class 3 is a designation that is applied to firearms dealers under the National Firearms Act. It covers the sale of weapons that are designated as “Title II” for individual possession.
If you love a good speed boat, car or anything else, then these are the vehicles for you. They’re insanely quick and usually pretty unique looking. Each of these machines is considered the fastest in its class.
Base class for presentations. A presentation is a special kind of dialog whose purpose is to present content on a secondary display.
Constructors ; Presentation(Context, Display, Int32). Creates a new presentation that is attached to the specified display using the optionally specified theme.
A presentation is a special kind of dialog whose purpose is to present content on a secondary display. A Presentation is associated with the target Display at
Base class for presentations. A presentation is a special kind of dialog whose purpose is to present content on a secondary display.
A Presentation is associated with the target Display at creation time and configures its context and resource configuration according to the
Base class for presentations. A presentation is a special kind of dialog whose purpose is to present content on a secondary display. A android.app.
import android.view.WindowManager.LayoutParams.WindowType;. import java.util.Objects;. /**. * Base class for presentations. * <p>. * A presentation is a
The Presentation class is a part of the Android SDK that allows you to create a separate window for displaying content on a secondary
savedInstanceState) { // Be sure to call the super class. super.
In the legacy artifact ( presentation ), WebPresentationFragment inherits from android.app.Fragment . Usage: Mirroring Presentation Classes. There are three
Create, edit, and collaborate on presentations from your Android phone or tablet with the Google Slides app. With Slides, you can: