In SelectionFragment, user.getId() gets the current logged in user's Facebook ID.
In MainActivity.java, I have an intent to start another activity.
I'm trying to figure out how to use the data from user.getId() in an intent in MainActivity.java:
Intent i = new Intent(getApplicationContext(), AllProductsActivity.class);
i.putExtra("EXTRA_FACEBOOK_ID","FB_ID_VALUE_GOES_HERE");
startActivity(i);
I've tried a lot of things on stack overflow and none of them have worked so far. Any help appreciated!!
Relevant code from SelectionFragment:
Facebook ID is collected:
private void makeMeRequest(final Session session) {
// Make an API call to get user data and define a
// new callback to handle the response.
Request request = Request.newMeRequest(session,
new Request.GraphUserCallback() {
@Override
public void onCompleted(GraphUser user, Response response) {
// If the response is successful
if (session == Session.getActiveSession()) {
if (user != null) {
// Set the id for the ProfilePictureView
// view that in turn displays the profile picture.
profilePictureView.setProfileId(user.getId());
// Set the Textview's text to the user's name.
userNameView.setText(user.getName());
// Set the Textview's text to the user's name.
userIdView.setText(user.getId());
}
}
if (response.getError() != null) {
// Handle errors, will do so later.
}
}
});
request.executeAsync();
}
-
private TextView userIdView;
-
userIdView = (TextView) view.findViewById(R.id.selection_user_id);
-
userIdView.setText(user.getId());
Relevant code from MainActivity:
private static final int SPLASH = 0;
private static final int SELECTION = 1;
private static final int SETTINGS = 2;
private static final int FRAGMENT_COUNT = SETTINGS +1;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
FragmentManager fm = getSupportFragmentManager();
fragments[SPLASH] = fm.findFragmentById(R.id.splashFragment);
fragments[SELECTION] = fm.findFragmentById(R.id.selectionFragment);
fragments[SETTINGS] = fm.findFragmentById(R.id.userSettingsFragment);
}
EDIT
After checking out the google documentation, I added the following to my MainActivity:
SelectionFragment fragment = (SelectionFragment) getSupportFragmentManager().findFragmentById(R.id.selectionFragment);
My understanding is that this allows me to connect to the fragment, but I can't figure out how to get the facebook id from the fragment now. I tried this, but the app crashes. I get a null pointer exception at this line:
String fbID = fragment.userIdView.getText().toString();