I am trying to open new Google map activity from my main activity, I pass the Extras in the main activity and check the intent everything is fine and all the information is there.When the new activity opens, if I check the information using the debug I can see that everything is fine too yet, when I am using getStringArrayExtra()
it always returns NULL.
Main Activity
mapIntent.putExtra("LAN_LIST", goodLan.toArray());
mapIntent.putExtra("LON_LIST", goodLon.toArray());
mapIntent.putExtra("HeadLine_LIST", goodheadline.toArray());
mapIntent.putExtra("Context_LIST", goodcontext.toArray());
startActivity(mapIntent);
Map Activity
Intent intent = getIntent();
lan = intent.getExtras().getStringArray("LAN_LIST");//does not work
lan = intent.getStringArrayExtra("LAN_LIST");//does not work too
lon = intent.getStringArrayExtra("LON_LIST");//same
Headline = intent.getStringArrayExtra("HeadLine_LIST");//same
Context = intent.getStringArrayExtra("Context_LIST");//same
I am not posting the log because I don't have any exceptions, all the variables get null
and that it.
Thank you!
When you are setting the value as array you could try like this for all:
mapIntent.putExtra("LAN_LIST", goodLan.toArray(new String[goodLan.size()]));
Assuming the Lists contain only Strings, this will work.
Alternately, in your MainActivity you could pass them as ArrayList using
mapIntent.putStringArrayListExtra("LAN_LIST", (ArrayList<String>) goodLan);
And then you could receive them at MapActivity as intent.getExtras().getStringArrayListExtra("LAN_LIST");
我所要做的就是将信息作为List传递。
您还必须添加activity的名称作为方法getStringArray的参数。
lan = intent.getExtras().getStringArray(MainActivity.LAN_LIST);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.