android - State Loss Management -
i've activity contains login fragment , activity b contains home fragment. i've start b login fragment after succesfully login request (async). i've callback listener inside login fragment:
onsuccess(result) { startactivity(b); }
today met nice bug: getting exception "illegalstateexception: can not perform action after onsaveinstancestate".
i think that's not bug, anyway don't know how workaround that. this blog post suggests avoid transaction inside async callback methods, yeah how? commitallowingstateloss() should used last resort: in case, should use inside home fragment transaction in activity b creation method?
basically, should start activity after async callback?
you should use onpostexecute(result) in asynctask:
private class logintask extends asynctask<parameters,...> { ... protected void onpostexecute(long result) { //if result successful start activityb } }
onpost fires after asynctask complete. runs on ui thread should solve problem.
put in main activity:
public void run(){ //code have after task completes }
then put in onsuccess:
mainactivity.runuionthread()
Comments
Post a Comment