I implemented one of the approaches suggested by @CommonsWare (and independently by Mark Allison in answer to my question on his blog). Thanks for your suggestions!
In review, THE PROBLEM was I couldn't keep a second screen presentation running in the background across Activity
invocations on a local device. This was because the Presentation
class is implemented as a subclass of Dialog
, and is therefore tied to an Activity
instance. So when a new Activity
started up, the second screen went back to mirroring (instead of displaying other content I was specifically generating for it).
THE SOLUTION was to refactor all "subordinate" Activities
into Fragments
of the original Activity
(i.e., the one that launched the second screen). Then, instead of calling startActivity()
, I start/stop the new Fragments
using FragmentTransactions
. The net effect is that the Activity that started the Presentation is still running, so the secondary display is no longer interrupted when a new Activity starts.
My case was further complicated by the fact that the top level Activity
(which starts the second screen) was actually a SherlockFragmentActivity
that uses a ViewPager
and FragmentStatePagerAdapter
-- so I had to cram all this into a Fragment
. It also required explicit management of ActionBar
tabs, menu items, and home icon.
Overall, I think the code is a little less transparent ... but it works!
NOTE: It's good that Google has implemented a secondary screen interface. But I'm not sure why they did it the way they did. Rather than shoe-horning the Presentation
class into Dialog
, it would have been nice if they provided a more general solution that could easily run in the background, i.e., regardless of foreground Activities
on the device. A solution like this would have saved me from a lot of code refactoring, as described above.