onCreate(...) is called twice after the device is rotated
<p>I have a question about rotating the Android device.  My code logs a static and non-static attribute in onCreate(...).</p>

<pre class="lang-java prettyprint-override"><code>import android.app.Activity;
import android.os.Bundle;
import android.util.Log;

public class MainActivity extends Activity {
    static int sn;
    int n;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        sn++;
        n++;

        Log.i("onCreate", String.format("sn=%d n=%d", sn, n));
    }
}
</code></pre>

<p>The screen orientation is portrait. When I first ran the code, I got:</p>

<pre><code>onCreate(): sn=1 n=1
</code></pre>

<p>After I rotated the screen to landscape, I got:</p>

<pre><code>onCreate(): sn=2 n=1
</code></pre>

<p>After I rotated the screen again to portrait, I got:</p>

<pre><code>onCreate(): sn=3 n=1
onCreate(): sn=4 n=1
</code></pre>

<p>My questions are:</p>

<ol>
<li>How can I prevent onCreate(...) to be called twice when the device is rotated back to portrait?</li>
<li>How can I save the value of non-static variable when the device is rotated?</li>
</ol>
