Я пытаюсь передать переменную из метода в другой без использования параметра. Я объявил значение глобально, но все же возвращаемое значение равно нулю, когда значение вызывается во втором методе
String profileName;//globally declared
protected void onCreate(Bundle savedInstanceState) {
// Initialize Facebook Login button
mCallbackManager = CallbackManager.Factory.create();
LoginButton loginButton = (LoginButton) findViewById(R.id.login_button);
loginButton.setReadPermissions("email", "public_profile");
loginButton.registerCallback(mCallbackManager, new FacebookCallback<LoginResult>() {
@Override
public void onSuccess(LoginResult loginResult) {
Log.d("Logger", "facebook:onSuccess:" + loginResult);
handleFacebookAccessToken(loginResult.getAccessToken());
GraphRequestAsyncTask request = GraphRequest.newMeRequest(loginResult.getAccessToken(), new GraphRequest.GraphJSONObjectCallback() {
@Override
public void onCompleted(JSONObject user, GraphResponse graphResponse) {
profileName=user.optString("name");
`//assigns the correct value here*`*
Toast.makeText(getApplicationContext(),profileName,Toast.LENGTH_SHORT).show();
}
}).executeAsync();
}
private void updateUI() {
Toast.makeText(getApplicationContext(),"You Logged Successfully",Toast.LENGTH_SHORT).show();
Intent intent=new Intent(Facebook.this,Add.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.putExtra("ProfileName",profileName );
//profileName is set to null though i am assigning the value in the method onCompleted**
startActivity(intent);
finish();
}