Android not restoring instance state -
i know similar questions have been asked none of solutions questions have been working me.
when go ahead , try save state of app, state of edittext views not being saved , restored. went ahead , commented out , put in temporary string save when app loads again, oncreate() method not print 'restoring instance state'
package com.fwumdesoft.udppacketsender; import android.support.v7.app.appcompatactivity; import android.os.bundle; import android.util.log; import android.view.view; import android.widget.edittext; import android.widget.toast; import java.io.ioexception; import java.net.datagrampacket; import java.net.datagramsocket; import java.net.inetsocketaddress; /** * posts udp message given data * target address on target port. */ class udppostactivity extends appcompatactivity { private static final string tag = "udppostactivity"; private static final string statetexttargethost = "com.fwumdesoft#targethost"; private static final string statetexttargetport = "com.fwumdesoft#targetport"; private static final string statetexthexdata = "com.fwumdesoft#hexdata"; private static final string statetextstringdata = "com.fwumdesoft#stringdata"; @override protected void oncreate(bundle savedinstancestate) { log.v(tag, "oncreate"); super.oncreate(savedinstancestate); setcontentview(r.layout.activity_udp_post); if (savedinstancestate != null) { // ((edittext) findviewbyid(r.id.txtaddress)).settext(savedinstancestate.getstring(statetexttargethost)); // ((edittext) findviewbyid(r.id.txtport)).settext(savedinstancestate.getstring(statetexttargetport)); // ((edittext) findviewbyid(r.id.txtdata)).settext(savedinstancestate.getstring(statetexthexdata)); // ((edittext) findviewbyid(r.id.txtstringdata)).settext(savedinstancestate.getstring(statetextstringdata)); string text = savedinstancestate.getstring(statetextstringdata); log.v(tag, "restoring instance state"); } } @override protected void onsaveinstancestate(bundle outstate) { // outstate.putstring(statetexttargethost, ((edittext)findviewbyid(r.id.txtaddress)).gettext().tostring()); // outstate.putstring(statetexttargetport, ((edittext)findviewbyid(r.id.txtport)).gettext().tostring()); // outstate.putstring(statetexthexdata, ((edittext)findviewbyid(r.id.txtdata)).gettext().tostring()); // outstate.putstring(statetextstringdata, ((edittext)findviewbyid(r.id.txtstringdata)).gettext().tostring()); super.onsaveinstancestate(outstate); outstate.putstring(statetextstringdata, "test"); log.v(tag, "saved instance state"); } @override protected void onrestoreinstancestate(bundle savedinstancestate) { super.onrestoreinstancestate(savedinstancestate); log.v(tag, "onrestore"); // ((edittext)findviewbyid(r.id.txtaddress)).settext(savedinstancestate.getstring(statetexttargethost)); // ((edittext)findviewbyid(r.id.txtport)).settext(savedinstancestate.getstring(statetexttargetport)); // ((edittext)findviewbyid(r.id.txtdata)).settext(savedinstancestate.getstring(statetexthexdata)); // ((edittext)findviewbyid(r.id.txtstringdata)).settext(savedinstancestate.getstring(statetextstringdata)); }
in logcat output "saved instance state" , "oncreate" not "restoring instance state" or "onrestore" when restarting app.
go debug mode , see if oncreate being called. have android:configchanges set in manifest?
Comments
Post a Comment