1

Let us say we have 2 activities A and B. A is mainactivity which logins to facebook and also tracks the access token using AccessTokenTracker class. According to documentation, system should stop tracking token in onDestroy() method of activity A. Problem is I want to keep tracking accessToken in activity B too. Activity B also needs accessToken for graph API call. If token expires in the Activity B, how can we keep track of it?

Anis Shrestha
  • 61
  • 1
  • 5

2 Answers2

0

How about saving it in SharedPreferences?

SharedPreferences preferences = getSharedPreferences(PREFS_NAME, MODE_PRIVATE);
preferences.edit().putString(TOKEN, token).apply();
mattfred
  • 2,689
  • 1
  • 22
  • 38
  • @matfred But access token is not string. I think even we change it into string using using AccessToken.getToken(), we cannot change it to accessToken later in next activity. – Anis Shrestha Jul 19 '15 at 04:49
0

If you need to share a parameter between your Acitivities, there are a couple of methods. Singleton is one of the easier one:

class DataHolder{

    private AccessToken ac;

    void setToken (AccessToken ac)
      {
       this.ac = ac;
      }

    AccessToken getToken()
      {
        return ac;
      }

}

If you want more details, read this.

Community
  • 1
  • 1
Kasra
  • 3,045
  • 3
  • 17
  • 34
  • I don't want to pass the data from activity to activity. I want to track the accessToken when I am on activity B. If access Token expires on activity B,I need to track it and get new access token. – Anis Shrestha Jul 19 '15 at 19:10