Android activities navigation flow problem
<p>I have activity A that starts activity B(singleInstance). In activity B there is a back button, which starts intent to activity A.</p>

<p>A -> B -> A</p>

<p>I want to achieve following behaviour:</p>

<p>User triggers B on A, after that press my back button, returns to activity A and press devices's hardware back button, which navigates him to device's home screen.</p>

<p>Now it looks like that: 
User triggers B on A, after that press my back button, returns to activity A and press devices's hardware back button, which navigates him again to activity A, then press back button again and open activity B. Then he presses back button and activity A occurs and it is an endless loop....</p>

<p>I can not use flag NO_HISTORY, because I want to save state of activity B from some other reasons. Activity B is a webBrowser so I have overloaded methods onSaveInstanceState and onRestoreInstanceState to save in cache website which was loaded.</p>

<p>Right now I overloaded onBackPressed method in activity A , by starting an intent to home screen, but it is not a good solution.</p>

<p>Do you have any other ideas?</p>

<p>Here is the code:</p>

<p>Activity A:
<code>Intent browser = new Intent(this, B.class);
this.startActivity(browser);</code></p>

<p>Activity B:
`   @Override
    public void onSaveInstanceState(Bundle savedInstanceState) {                                                                                           super.onSaveInstanceState(savedInstanceState);<br>
            callWebViewMethod("saveState", new Class[] { Bundle.class }, 
                    new Object[] { savedInstanceState });
    }
    @Override
    public void onRestoreInstanceState(Bundle savedInstanceState) {
        super.onRestoreInstanceState(savedInstanceState);</p>

<pre><code>    callWebViewMethod("restoreState", new Class[] { Bundle.class }, 
            new Object[] { savedInstanceState });
}   
@Override
public void onBackPressed() {
    if (webView != null) {
        if ( ( Boolean )callWebViewMethod( "canGoBack" ) )
        {
            callWebViewMethod("goBack");
        }
        else
        {
            startActivity( getBackIntent() );
        }
    }
}
private Intent getBackIntent() {
    Intent i = new Intent();
    // some code here           
    i.setClass(this, A.class);
    return i;
}`
</code></pre>
