android - Wrong reference to Activity in listener after screen rotation -
i have problem google maps api. after rotate screen have wrong/old reference activity. i"am using "mmapfragment.setretaininstance(true);". "pact" activity. logging gives me hascode of activity not same(look example).
private void setupmapifneeded() { if (map != null) { log.d(h.tag, "setupmapifneeded" ); log.d(h.tag, pact.tostring() + " set new onclicklistener"); map.setoninfowindowclicklistener(new oninfowindowclicklistener(){ @override public void oninfowindowclick(marker marker) { log.d(h.tag, pact.tostring() + " click"); } }); } }
loggin example
before rotation:
- mainapp@422fa1c0 mainapp created
- mainapp@422fa1c0 set new onclicklistener
- mainapp@422fa1c0 click
after rotation:
- mainapp@42b291f0 mainapp created
- mainapp@42b291f0 set new onclicklistener
- mainapp@422fa1c0 click
do need more code?
onretaininstance preserve fragment instance , not activity. need update activity reference 1 passed in
onattach(activity)
Comments
Post a Comment