java安卓:通过intent传递字符串ArraryList。收到的值为空
我通过一个intent传递一个字符串数组列表,当我从bundle中得到它时,我得到一个空值。你知道错误是什么吗?是因为我在newMyFriendRequest方法中使用它吗
final Bundle extras = new Bundle();
extras.putString(EXTRA_PROFILENAME, profile.getFirstName());
extras.putString(EXTRA_PROFILEID, profile.getId());
final ArrayList<String> listids = new ArrayList<String>();
final ArrayList<String> listnames = new ArrayList<String>();
GraphRequestBatch batch = new GraphRequestBatch(
GraphRequest.newMyFriendsRequest(accessToken, new GraphRequest.GraphJSONArrayCallback() {
@Override
public void onCompleted(JSONArray jsonArray, GraphResponse response) {
// Application code for users friends
System.out.println("getFriendsData onCompleted : jsonArray " + jsonArray);
System.out.println("getFriendsData onCompleted : response " + response);
try {
for(int i=0; i<jsonArray.length(); i++)
{
JSONObject jsonObject = jsonArray.getJSONObject(i);
listids.add(jsonObject.getString("id"));
listnames.add(jsonObject.getString("name"));
System.out.println("Iteration: " + i);
System.out.println("Name: "+jsonObject.getString("name") );
System.out.println("ID: "+jsonObject.getString("id") );
}
extras.putStringArrayList("names", listnames);
extras.putStringArrayList("ids", listids);
System.out.println("Names: " + listnames);
System.out.println("IDs: " + listids);
} catch (Exception e) {
e.printStackTrace();
}
}
})
);
batch.addCallback(new GraphRequestBatch.Callback() {
@Override
public void onBatchCompleted(GraphRequestBatch graphRequests) {
// Application code for when the batch finishes
}
});
batch.executeAsync();
Intent intent = new Intent(getActivity(), MainLobby.class);
intent.putExtras(extras);
startActivity(intent);
在活动OnCreate方法中:
intent = getIntent();
Bundle extras = intent.getExtras();
//value is null not passing correctly
listids = extras.getStringArrayList("ids");
listnames = extras.getStringArrayList("names");
System.out.println("MainLobby");
System.out.println("Name: " + listnames);
System.out.println("User Logged In: " + user_name);
# 1 楼答案
您应该将此代码:
就在
GraphRequestBatch
内的for循环之后,因为根据开发人员站点在数据出现在意图中之前,下一个活动已经开始
这应该有用,但我自己没试过