tabs - How to solve Can not perform this action after onSaveInstanceState in android -
hi developing small android application in using sherlock actionbar. application contains following things. 1 main activity contains 2 fragments , 1 sample activity. want on button click inside fragment 1 start new sample activity. starting sample activity result. on activity result want swap tab tab2 tab. did in following way
@override public void onclick(view v) { // todo auto-generated method stub toast.maketext(getsherlockactivity(), "click on button", toast.length_short).show(); //getactivity().getactionbar().setselectednavigationitem(1); intent intent = new intent(getactivity(), sampleactivity.class); startactivityforresult(intent, 7); } and on activity result want
@override @suppresslint("newapi") public void onactivityresult(int requestcode, int resultcode, intent data) { super.onactivityresult(requestcode, resultcode, data); if(requestcode == 7) { getsherlockactivity().getsupportactionbar().setselectednavigationitem(1); } } so when tried getsherlockactivity().getsupportactionbar().setselectednavigationitem(1); shows me following error :
08-08 16:05:21.596: e/androidruntime(6885): fatal exception: main 08-08 16:05:21.596: e/androidruntime(6885): java.lang.runtimeexception: failure delivering result resultinfo{who=null, request=65543, result=0, data=null} activity {com.example.sampletabapp/com.example.sampletabapp.mainactivity}: java.lang.illegalstateexception: can not perform action after onsaveinstancestate any 1 having solution this.need thank you.
here sample project regarding issue https://www.dropbox.com/s/0d61i9ccol189tv/sampletabappzip.tar.gz. can check actual problem. 1 having solution please help. thank you.
to avoid conflicts immediate execution on ui thread during lifecycle methods, can use various post() methods or implement own handler.
i prefer handler pattern.
i recommend handler declared private static inner class, , have hold weakrefence whatever manipulating, fragment. weak reference avoid memory leaks if fragment repeatedly run through it's life cycle methods.
private static myhandler extends handler { private final weakreference<myfragment> ref; public myhandler(myfragment fragment) { ref = new weakreference<myfragment>(fragment); } @override public void handlemessage(message message) { myfragment fragment = ref.get(); if (fragment != null) { //do whatever want do. //for example: fragment.somecallbackmethod(); } } } then in fragment, have send message handler inside onclick() method
@override public void onclick(view v) { handler.sendmessage(new message()); }
Comments
Post a Comment