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
很高興幫助..! –