onDestroy for making data persistent and sync with the server
<p>I have a little problem to detect when the application is finished. I need to do some actions onDestroy like save the parameters into the database and make a final connection to the server.</p>

<p>The problem is that if I put the code in <code>onDestroy</code> its is called when the orientation changes for example. Putting</p>

<pre><code>android:configChanges="orientation|keyboardHidden"
</code></pre>

<p>in the manifest for that activity the landscape/portrait layouts don't swap. And adding </p>

<pre><code>@Override
public void onConfigurationChanged(Configuration newConfig) {
    super.onConfigurationChanged(newConfig);
    setContentView(R.layout.main);
}
</code></pre>

<p>Changes the layouts but the buttons and labels do not get the <code>onClickListeners</code> and the text labels correctly. How can I solve that? Thanks</p>
