Can't override onBackPressed neither onKeyDown - Android -


i'm implementing app tabhost. in 1 of tabs i'm executing more 1 activities (activitygroup).

for example: i'm in activity one, after clicking in listview go activity 2 in same tab. problem when press button, application closes , want go activity one. i've overwritten onbackpressed() method, onkeydown method , won't called, not being fired. i've seen lot of posts same problem of solutions shown wont work.

would glad help!

creating tabs:

protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.activity_main_tab);      tabhost fichas = gettabhost();     fichas.setup();           tabhost.tabspec spec=fichas.newtabspec("tab1");     intent = new intent(getapplicationcontext(), allproductsactivity.class);     spec.setcontent(i);     spec.setindicator("hoy");     fichas.addtab(spec);      tabhost.tabspec spec2=fichas.newtabspec("tab2");     intent i2 = new intent(getapplicationcontext(), queactivity.class);     spec2.setcontent(i2);     spec2.setindicator("que");     fichas.addtab(spec2);      spec=fichas.newtabspec("tab3");     spec.setcontent(r.id.cuando);     spec.setindicator("cuando");     fichas.addtab(spec);      spec=fichas.newtabspec("tab4");     spec.setcontent(r.id.donde);     spec.setindicator("donde");     fichas.addtab(spec);  } 

on queactivity.class i'm implementing onclicklistener show new activity in same tab:

public void onitemclick(adapterview<?> a, view v, int position, long id) {             //creo el nuevo objeto para poder llamarlo              intent intent = new intent(queactivity.this, productoscategorias.class);              //creo la informacion para pasar entre actividades             bundle informacion= new bundle();             intent.putextra("eventos",categorias.get(position).geteventos());             toast.maketext(getapplicationcontext(), "has seleccionado "+ categorias.get(position).getnombre(), toast.length_short).show();             //new activity             intent.addflags(intent.flag_activity_clear_top);             view view = (getlocalactivitymanager().startactivity("productos", intent)).getdecorview();             setcontentview(view);                                            } 

activity requested. here want override onbackpressed()

protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.activity_productos_categorias);     //do stuff here      }); 

outside oncreate method i'm overriding:

public void onbackpressed(){     system.out.println("fires");     //go other intent } 

the problem when press key don't overrided method fired, insted of application gets closed

this because in activitygroup onactivityresult event called on activitygroup class , not in activity calling it.

this stack overflow question can solve problem:

issue onactivityresult in tab activity


Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

css - Firefox for ubuntu renders wrong colors -