# \afterpage issue with \lstlisting

I have issue with \afterpage command and \lstlisting, it's add one blank page after beginning code listing, and after blank page is two of my command.

\appendix
\section*{APPENDIX A}

\newcommand\mycontinue{\noindent\makebox[\linewidth][r]{CONTINUE APPENDIX  A}\afterpage{\mycontinue}}

\afterpage{\mycontinue}

\subsection*{Some title}
\lstinputlisting{code.java}


Answer for question for after page: http://tex.stackexchange.com/a/54292/14208

-
Can you pl. post a complete MWE showing the problem? –  Harish Kumar May 4 '12 at 8:42

You were lucky you only got one page, as far as I can see that definition encodes a recursive infinite loop as \mycontinue is defined in terms of itself. (Martin's original answer reset it on the last page)
I thought from your previous question that you wanted the text to be in the heading rather than the page block in which case just defining a suitable page style based on headings and going \pagestyle{headings} would be enough. That would put the section title in the heading you'd just have to change the definition slightly (using fancyhdr package most easily) to add the "continued" text.
yes but you can change the pagestyle just for specific sections, if you want the text in the main body something like afterpage is perhaps the way to go but afterpage is always pushing the boundaries of what is reasonable to do. On the other hand changing the page headings via \mark set by sectioning commands is a robust feature supported by the basic underlying Tex engine. –  David Carlisle May 4 '12 at 10:03