Android Facebook 登录集成 - 个人资料图片问题
Android Facebook Login Integration - Issue in Profile Picture
更新
问题 1 已解决
我通过将 Glide 的上下文从 getApplicationContext 更改为 HomeActivity.this 并快速加载图像,解决了个人资料图片未加载的问题。 :)
但是,我仍然需要您帮助解决其他两个问题。如果我这样做是对还是错,以及如何避免该错误。
问题一
到目前为止,我已成功连接我的应用程序以进行 facebook 登录,但问题是个人资料图片。
我所做的是创建 2 activity:-
1. Activity 1中的Facebook登录按钮
2. App.
首页Activity
如果用户已登录,则转到 Activity 2,如果未登录,则转到 activity 1。
在 activity 1,我已经获取了基本详细信息,例如出生日期和电子邮件地址,因为不需要使用 GraphRequest 获取姓名和个人资料图片。 (为了能够保存在我的服务器上)
在activity 2,我已经获取了用户名和头像。这是代码:-
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();
}
}
2 天前,个人资料图片加载正常,但从今天开始就完全无法加载了。
问题二
我的另一个问题是,有时我在登录并进入主页时会收到一条错误消息 Activity,这是相同的快照:-
问题3
最后一个问题是如何在从 activity 2 按下后退时关闭整个应用程序。
我现在所做的是在 Activity 1 上使用处理程序,这样就不会出现上述错误,然后在 activity 1 和 [=56 上使用 Intent 和下面的方法使用 finish() 方法=] 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();
}
更新
问题 1 已解决
我通过将 Glide 的上下文从 getApplicationContext 更改为 HomeActivity.this 并快速加载图像,解决了个人资料图片未加载的问题。 :) 但是,我仍然需要您帮助解决其他两个问题。如果我这样做是对还是错,以及如何避免该错误。
问题一
到目前为止,我已成功连接我的应用程序以进行 facebook 登录,但问题是个人资料图片。 我所做的是创建 2 activity:- 1. Activity 1中的Facebook登录按钮 2. App.
首页Activity如果用户已登录,则转到 Activity 2,如果未登录,则转到 activity 1。
在 activity 1,我已经获取了基本详细信息,例如出生日期和电子邮件地址,因为不需要使用 GraphRequest 获取姓名和个人资料图片。 (为了能够保存在我的服务器上)
在activity 2,我已经获取了用户名和头像。这是代码:-
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();
}
}
2 天前,个人资料图片加载正常,但从今天开始就完全无法加载了。
问题二
我的另一个问题是,有时我在登录并进入主页时会收到一条错误消息 Activity,这是相同的快照:-
问题3
最后一个问题是如何在从 activity 2 按下后退时关闭整个应用程序。 我现在所做的是在 Activity 1 上使用处理程序,这样就不会出现上述错误,然后在 activity 1 和 [=56 上使用 Intent 和下面的方法使用 finish() 方法=] 2:-
public void onBackPressed() {
onStop();
onDestroy();
finish();
}
To Question 3
from Activity 1 create a function
onActivityResult
and be sure to use thestartActivityForResult
to call the Activity 2 instead ofstartActivity
.
@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();
}