I have an Activity which when calling another Activity normally calls the other screen, the problem I have to exit the other screen twice to return to the first. I'm calling Activity in an event of a EditText
, while enter on the keyboard:
campoBusca.setOnKeyListener(new View.OnKeyListener() {
@Override
public boolean onKey(View arg0, int onKey, KeyEvent arg2) {
// se pressionar enter
if (onKey == KeyEvent.KEYCODE_ENTER) {
//chama a tela passando por parametro a url
Intent telaSegmento = new Intent(MainActivity.this, SegmentoView.class);
Bundle bundleParametro = new Bundle();
URL = "www.xxx";
bundleParametro.putString("id", URL);
telaSegmento.putExtras(bundleParametro);
startActivity(telaSegmento);
return false;
}
}
}
Activity 2:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// carrega o layout onde contem o ListView
setContentView(R.layout.empresa_lista);
ActionBar bar = getActionBar();
bar.hide();
Intent dadosRecebidos = getIntent();
if (dadosRecebidos != null) {
Bundle parRecebidos = dadosRecebidos.getExtras();
if (parRecebidos != null) {
URL = parRecebidos.getString("id");
}
}
}
@Override
public void onBackPressed() {
finish();
}
When invoking the onBackPressed()
method, it closes the activity, but it is as if it were another, so I have to send it out again, then it goes back to the first Activity . Someone help me?