2
我通过一个意图传递一个字符串数组列表,当我从捆绑中获得它,我得到一个空值。你知道错误是什么吗?是因为我在newMyFriendRequest方法中使用它吗?Android:通过意图传递字符串ArraryList。价值收到null
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);
感谢它的工作 – akalanta
很高兴帮助..! –