0

I'm developing an application based on Facebook 4.0 login. The user can log in in Login.activity and then the main.Activity is shown.

After user successfully logged in, AccessToken.getCurrentAccessToken() is not null and I'm able to perform a Graph Request.

 ParseFacebookUtils.logInWithReadPermissionsInBackground(...)

Then

AccessToken token = AccessToken.getCurrentAccessToken();
if(token != null)
    GraphRequest request = GraphRequest.newMeRequest(token, ...)

But then after my Intent, AccessToken.getCurrentAccessToken() is always null.

Do you have any idea why AccessToken cannot be used across acitivies ?

Thanks,

John smith
  • 355
  • 4
  • 17

1 Answers1

0

You can declare your AccessToken as static, in MainActivity, then initialize it in onCreate, and then you can use it in other activities.

Or a best way, is to share it throw your intent, look here, What's the best way to share data between activities?

Send data inside intents

Intent intent = new Intent(FirstActivity.this, SecondActivity.class);
intent.putExtra("some_key", value);
intent.putExtra("some_other_key", "a value");
startActivity(intent);

On the second activity:

Bundle bundle = getIntent().getExtras();
int value = bundle.getInt("some_key");
String value2 = bundle.getString("some_other_key");

PS: the snipped code was toked from the shared post

Community
  • 1
  • 1
Alin Stelian
  • 861
  • 1
  • 6
  • 16
  • But I guess thah AccessToken.getCurrentAccessToken() is already static. I don't understand why it gets null after my intent .. – John smith Jan 29 '16 at 10:44
  • Have you passes the data from your activty throw that intent ? – Alin Stelian Jan 29 '16 at 10:49
  • I have just done this.startActivity(new Intent(this, MainActivity.class)); in my Login.acitivity when user succesfully logged in – John smith Jan 29 '16 at 10:53
  • ok, good. But you must share that date throw your activities, and you can do through your intents or by making a variable static. here is an example to how could you passed it . Send data inside intents Intent intent = new Intent(FirstActivity.this, SecondActivity.class); intent.putExtra("some_key", value); intent.putExtra("some_other_key", "a value"); startActivity(intent); On the second activity: Bundle bundle = getIntent().getExtras(); int value = bundle.getInt("some_key"); String value2 = bundle.getString("some_other_key"); PS: this is toked from the shared post. – Alin Stelian Jan 29 '16 at 11:08