Android: OnKeyDown problem
<p>I am using onKeyDown for handling the back button but on pressing the back button the application exits whereas it should go back to the previous activity. Following is the code i'm using:</p>

<pre><code>public class NewsDetails extends Activity{

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Intent myIntent = getIntent(); 
    String id = myIntent.getStringExtra("content_id");
    String title = myIntent.getStringExtra("title");
    String nTitle = "&lt;font color='white'&gt;"+title+"&lt;/font&gt;";
    setContentView(R.layout.web);

    super.onStart();
    final String mimeType = "text/html";
    final String encoding = "utf-8";

    /*Title*/
    WebView wv = (WebView)findViewById(R.id.wv1);
    WebSettings webSettings = wv.getSettings();
    webSettings.setDefaultFontSize(15);
    wv.setBackgroundColor(Color.BLACK);
    wv.loadData(nTitle, mimeType, encoding);

    /*Body*/
    String xml = XMLfunctions.getBodyXML(id);
    String result = xml.replaceAll("&lt;p&gt;", "&lt;p&gt;&lt;div align=\"justify\"&gt;");
    String nXml = result.replaceAll("&lt;/p&gt;", "&lt;/div&gt;&lt;/p&gt;");
    String nBody = "&lt;font color='white'&gt;"+nXml+"&lt;/font&gt;" ;
    WebView wv1 = (WebView)findViewById(R.id.wv2);
    wv1.setBackgroundColor(Color.BLACK);
    WebSettings webSettings1 = wv1.getSettings();
    webSettings1.setDefaultFontSize(10);
    wv1.loadData(nBody, mimeType, encoding);

}

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if ((keyCode == KeyEvent.KEYCODE_BACK)) {
        Intent intent = new Intent(NewsDetails.this, TopNewsActivity.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        View view = TopNewsGroup.group.getLocalActivityManager().startActivity("ShowNews", intent).getDecorView();
        TopNewsGroup.group.setContentView(view);
        return true;
    }
    return super.onKeyDown(keyCode, event); 

}

public boolean onCreateOptionsMenu(Menu menu) {

    super.onCreateOptionsMenu(menu);
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.optionsmenu, menu);
    return true;
}

public boolean onOptionsItemSelected(MenuItem item){

    switch (item.getItemId()){

        case R.id.refresh:
                startActivity(new Intent(this, NewsDetails.class));
                return true;

        case R.id.search:
                startActivity(new Intent(this, SearchActivity.class));
                return true;

        case R.id.info:
                startActivity(new Intent(this, NewsDetails.class));
                return true;

        case R.id.exit:
                finish();
                return true;
    }
  return false;
}



}
</code></pre>
