The Opus 9 (D. 365) collection was published in 1821; as most of the waltzes of D. 779 were probably composed in 1822-23, it is entirely plausible that Schubert might have played a version of D365n6 at some point not long after the publication of Opus 9 and decided to use its distinctive opening formula to improvise a new waltz. The likelihood is increased by the fact that D365n6 was apparently among Schubert's favorites: as Litschauer reports, it is among only six Schubert waltzes that appear three times in different manuscripts and one of only two found in manuscript copies made by one of his friends (Litschauer 1995, 4). The fact that some of these are variants is all the more intriguing. The first of the three manuscript versions (in 9 Deutsche (1819)) is identical to the published version, but the second (in 2 Deutsche (1821)) is striking in that it gives a fully realized Bb minor 6/3 chord in the left hand of bars 1-2, whereas the third (in 4 Deutsche (undated)) combines the first strain of D365n6 with the second strain of No. 7 from the same set (see Litschauer 1989).
Thus, we can imagine the new waltz starting as depicted at (a) in the graphic below: as necessary, vamping to establish the waltz meter and tempo for the dancers (or to gather one's thoughts), then open with a slight rhythmic variant of the figure in D365n6. The voice leading formula (second line in (a)) is varied too from the moment that F# becomes the upper voice (by the end of the first full bar of melody), but that is also where the trouble begins (third line in (a)), also realized as an initial attempt at a complete phrase in (b), which has a rather flat ending that allows the suspensions to drag the upper-voice melody down through ^4 and ^3).
Level (c) shows this ending again with the lead-in to the repetition of the phrase. Here is the first inspired moment in what has so far been a rather dismal effort: the hemiola rhythm of the initial gesture has taken control by now and the "turn" in four eighth notes gracefully (and convincingly) gathers energy that is directed toward the F#. Finishing out this varied repetition of the first strain, Schubert brings the upper voice down from its perch on ^6 and ^5 with a conventional ländler cadence that strikes ^1 but leaves the register of ^3 open. This cadence will also close the second strain of an 8 + 8 recomposition in Example 4.34.) Like the descent to ^3 in the first statement, this cadence seems weak.
Thus, we can imagine the new waltz starting as depicted at (a) in the graphic below: as necessary, vamping to establish the waltz meter and tempo for the dancers (or to gather one's thoughts), then open with a slight rhythmic variant of the figure in D365n6. The voice leading formula (second line in (a)) is varied too from the moment that F# becomes the upper voice (by the end of the first full bar of melody), but that is also where the trouble begins (third line in (a)), also realized as an initial attempt at a complete phrase in (b), which has a rather flat ending that allows the suspensions to drag the upper-voice melody down through ^4 and ^3).
Level (c) shows this ending again with the lead-in to the repetition of the phrase. Here is the first inspired moment in what has so far been a rather dismal effort: the hemiola rhythm of the initial gesture has taken control by now and the "turn" in four eighth notes gracefully (and convincingly) gathers energy that is directed toward the F#. Finishing out this varied repetition of the first strain, Schubert brings the upper voice down from its perch on ^6 and ^5 with a conventional ländler cadence that strikes ^1 but leaves the register of ^3 open. This cadence will also close the second strain of an 8 + 8 recomposition in Example 4.34.) Like the descent to ^3 in the first statement, this cadence seems weak.
At this point, the decision has to be made whether to set the new waltz in a two or three-part form, but for our purpose here, Schubert's choice makes little difference. I will assume that he composes a contrasting second strain (in the manner of D365n5). The dancing continues, and I imagine that Schubert plays a trio (perhaps one of the Ab major waltzes from D. 365 transposed to A major), but the awkwardness of the newly invented waltz bothers him, and he returns to it. This time around, the first phrase and most of the second are as we know them in the published version, but the cover-tone-qua-melody, now much more insistent than in the first attempt, brings about the second inspired moment, the cadence that lifts the upper register to ^8 (see the lower line in (d)).
Having reached the register of ^8 (A5), Schubert decides to stay there, perhaps expecting to use G#5 to initiate a cycle of fifths sequence as in (e'). For reasons unknown (which might include a simple lapse of attention during a long evening of playing), he decides to ground the contrasting middle of a small ternary form in a tonicization of the C# major supporting that G#5. There are a few examples of this design, where the contrasting middle closes in the tonicized key, and the reprise returns to the main key without modulation, but in this case the design will not work because the theme starts on a non-tonic position one half-step above C#.The third and last inspired moment, then, is to take advantage of yet another motion upward to carry the melody into the pianoforte's thin-toned and ethereal upper octave where the reprise begins in the final version.
Schubert chose to keep the A Major Waltz and eventually found it a place in the D. 779 collection, but I fancy it was not because of its odd combination of counterpoint and dance topoi or even its dramatic tonal contrast (something Schubert is known to have liked), but instead for the sake of its charming two-tiered melody. I imagine one of his musically skilled friends, perhaps Josef von Spaun, coming over after hearing several repetitions of the Waltz and whispering, "Schön, zärtlich," while the dance continued.
References:
Litschauer, Walburga. "Franz Schuberts Tänze: Zwischen Improvisation und Werk." Musiktheorie10/1 (1995): 3-9. Litschauer, Walburga, ed. Franz Schubert. Neue Ausgabe sämtlicher Werke, Series 7, part 2: Werke für Klavier zu zwei Händen, Band 6: Tänze I. Kassel: Bärenreiter, 1989.