java - How to pass a string Arraylist from one activity to another? -


now tried use intent extra's pass , receive through bundle string array list reason list never passes, when try use get(0) retrieve first string list null pointer error, can please me on this?

first activity (signup activity):

 public static final string string_array = "geoquiz.android.bignerdranch.com.string_array";  final arraylist<string> mystringarray = new arraylist<>(); mystringarray.add(username.gettext().tostring()); mystringarray.add(firstname.gettext().tostring()); mystringarray.add(lastname.gettext().tostring());  intent = new intent(signupactivity.this,loginactivity.class); i.putextra("string_array", mystringarray); startactivity(i); 

second activity (login activity):

final bundle stringarraylist = getintent().getextras(); final arraylist<string> stringarray = new arraylist<> ();  stringarray = stringarraylist.getstringarraylist("string_array");  if(username.gettext().tostring().equals(stringarray.get(0))) toast.maketext(loginactivity.this, "you have logged in!", toast.length_short).show(); 

instead of i.putextra() use i.putstringarraylistextra().

also, add log entry make sure array populated expect.

log.i("mystringarray", mystringarray.tostring()); intent = new intent(signupactivity.this,loginactivity.class); i.putstringarraylistextra("string_array", mystringarray); //modified startactivity(i); 

also, take out final in code:

final bundle stringarraylist = getintent().getextras(); //final arraylist<string> stringarray = new arraylist<> (); //no need line arraylist<string> stringarray = stringarraylist.getstringarraylist("string_array"); //just declare , assign 

see documentation here


Popular posts from this blog

c# - ODP.NET Oracle.ManagedDataAccess causes ORA-12537 network session end of file -

matlab - Compression and Decompression of ECG Signal using HUFFMAN ALGORITHM -

utf 8 - split utf-8 string into bytes in python -