简体   繁体   中英

Android Facebook Login Integration - Issue in Profile Picture

UPDATE

Question 1 Solved

I have solved the issue of profile pic not loading by changing the context of Glide from getApplicationContext to HomeActivity.this and image loaded quickly. :) But still, I need your help with other two questions. If I am doing it right or wrong and how to avoid that error.


Question 1

So far, I have successfully connected my app for facebook login, but the issue is the profile picture. What I have done is created 2 activity:- 1. login button of Facebook in Activity 1 2. Home Activity of App.

If the user is logged in, it goes to Activity 2 and if not he goes to activity 1.

On activity 1, I have fetched basic details like dob and email address as name and profile picture doesn't need to be fetched using GraphRequest. (To be able to save on my server)

On activity 2, I have fetched the user name and profile picture. Here's the code:-

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_home);
    im = (ImageView) findViewById(R.id.img);
    name = (EditText) findViewById(R.id.name);
    try {
         String url =  Profile.getCurrentProfile().getProfilePictureUri(150,150).toString();
            name.setText(" "+Profile.getCurrentProfile().getName()+"\n"+Profile.getCurrentProfile().getId());
         Glide.with(getApplicationContext()).load(url).into(im);
    } catch (Exception e){
            Toast.makeText(this, "Error : "+e , Toast.LENGTH_SHORT).show();
        }
}

Until 2 days back, profile pic was loading fine but from today it's not loading at all.

Question 2

Another question, I have is that sometimes I get an error message when I log in and get in Home Activity, here's the snapshot of the same:-

在此处输入图片说明

Question 3

The last question is how to close the entire app on back pressed from activity 2. What I have done right now is use handler on Activity 1 so that the above error doesn't come and then use Intent and below that use finish() method on activity 1, and on activity 2:-

public void onBackPressed() {
    onStop();
    onDestroy();
    finish();
}

To Question 3

from Activity 1 create a function onActivityResult and be sure to use the startActivityForResult to call the Activity 2 instead of startActivity .

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    startActivityForResult(new Intent(this, ActivityTwo.class), 1);
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (resultCode == RESULT_OK) {
        if (data.getBooleanExtra("EXIT", false)) {
            finish();
        }
    }
}

and to close the entire app from Activity 2 using the onBackPressed. don't forget to remove the super.onBackPressed()

@Override
public void onBackPressed() {
    // super.onBackPressed();
    Intent intent = new Intent();
    intent.putExtra("EXIT", true);
    setResult(RESULT_OK, intent);
    finish();
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM