android - How do I save a textView -
how save textview when close , relaunch activity text still there?
protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_current_homework); intent intent = getintent(); string message = intent.getstringextra(addnewhomework.extra_message); textview textview = (textview) findviewbyid(r.id.textview99); textview.settext(message);
save text textview.gettext()
using sharedpreference
or other in ondestroy
.then read in oncreate
.
@override public void oncreate(bundle savedinstancestate, persistablebundle persistentstate) { super.oncreate(savedinstancestate, persistentstate); setcontentview(r.layout.main); //todo initialization sharedpreferences preferences = getapplicationcontext()// .getsharedpreferences("file_name", context.mode_private); mtextview.settext(preferences.getstring("key_name","")); } @override protected void ondestroy() { super.ondestroy(); final string text = mtextview.gettext(); final sharedpreferences.editor editor = getapplicationcontext()// .getsharedpreferences("file_name", context.mode_private)// .edit();// editor.putstring("key_name", text).commit(); }
Comments
Post a Comment