In one of my apps I have a situation where a user enters a page and a progressbar is shown until the server returns a response. If the server returns an error or the user has no internet (or whatever other problem) an imageview is shown with an error msg underneath. Here's my question: is it better to put the layout with the imageview and error msg inside the regular layout xml for the activity with visibility=gone and then make it visible if the error occurs, or is it better to make a seperate layout.xml just for errors and do a setcontentview to that if the error occurs? If I use setcontentview to another layout then the user will see a white flash as the new layout inflates, which I don't like so much.. on the other hand, keeping the error layout inside the regular layout probably has a memory penalty for something that usually won't be see by a regular user. Of course, there's a third option - add the error screen programmatically - but that has a problem of complexity if the layout of the error screen is more involved. What is the most efficient option?
pseudocode follows:
<LinearLayout
android:id="@+id/mainLayout"
>
.. layout code
<LinearLayout
android:id="@+id/errorLayout"
android:visibility="gone"
>
</LinearLayout>
</LinearLayout>
Edit: the final solution that I used involved a combination of ViewStub in certain cases (where the background activity need not be visible, but I don't want to consume memory on something that might not be shown) and DialogFragment (where the background activity needs to be shown through in transparency). This question prompted a vigorous offline debate among a number of android developers I know - some of whom supported the activity answer that was given below because it would best support material design styling, and others who supported using a dialogfragment because using an activity for something like this was probably overkill (extra class, need to add it to manifest, duplicate toolbar logic, etc.). Thanks to everyone who contributed.
Second edit: After working on this problem some more I'm not so sure about the dialogfragment solution after all. If you display an error on screen and you want the user to think that it's an organic part of the screen then the top toolbar has to be clickable. A dialogfragment leaves the top toolbar visible but clicks on it are not registered since even when the dimensions of the dialogfragment don't take up the entire screen it still sits in its own layer on the "whole" screen in the fragmentmanager and steals all the clicks. I'm tending to think that the only way of really doing this properly is with a viewstub.