Android: getSharedPreferences for session -


okay, check source code:

public void checksession() {     sharedpreferences session = getsharedpreferences(prefs_name, 1);      string getsession = session.getstring("session", null);     toast.maketext(this, getsession, toast.length_short).show();     if(getsession.length() > 30) {         intent menu = new intent(this, menu.class);         startactivity(menu);         finish();     }      else      {        } } 

the problem "first time users" crush.

when disable function, run app , login code creates session. after when logout, , restart app - there's no problem. ideas?

first time app runs , don't have value stored in sharedpreference "session" return null default value. getsession().length result in nullpointerexception.

you should instead:

string getsession = session.getstring("session", ""); 

Comments

Popular posts from this blog

c# - how to write client side events functions for the combobox items -

exception - Python, pyPdf OCR error: pyPdf.utils.PdfReadError: EOF marker not found -