[英]Android - Facebook login dialog and progress indicatior keeps popping out upon logging in
我已经在运行Android
应用程序中实现了Facebook
功能。 当用户按下Facebook
ImageButton
,它将启动身份验证过程(SSO)。 然后在用户的facebook
墙上发布信息。 一切都在模拟器上顺利运行。 能够张贴在墙上并能够查看。
但是,在实际设备上进行测试时,用户按下ImageButton
之后会出现一个问题。 ProgressDialog
会不断弹出,并且不会停止。 用户将需要通过按设备上的“ Home
按钮来关闭程序。
可能是什么问题呢? 我没有在Facebook.java
类中更改任何代码
Adapter.java
ImageButton fbBtn = (ImageButton) view.findViewById(R.id.fb);
fbBtn.setOnClickListener(
new Button.OnClickListener() {
public void onClick(View v)
{
taskListener.doAuthentication();
taskListener.postToWall(data[position], text[position], name[position]);
System.out.println(text[position]);
}
}
);
public static interface FBookTaskListener{
public void doAuthentication();
public void postToWall(String data, String text, String name);
}
Activity.java
protected class TheTask extends AsyncTask<Void, Void, MyResultClass >{
protected void onPreExecute() {
dialog = ProgressDialog.show(Activity.this, "Retrieving Information", "Please wait for a few seconds...", true, false);
dialog.setCancelable(true);
}
protected MyResultClass doInBackground(Void... params) {
searchContent();
MyResultClass result = new MyResultClass();
result.mStrings = mStrings;
result.dStrings = dStrings;
result.date = date;
result.name = name;
return result;
}
@Override
protected void onPostExecute(MyResultClass result) {
dStrings = result.dStrings;
mStrings = result.mStrings;
date = result.date;
name = result.name;
LazyAdapter adapter = new Adapter(Activity.this, mStrings, dStrings, name);
list.setAdapter(adapter);
adapter.setTaskListener(new FBookTaskListener(){
public void doAuthentication()
{
// here all your FB authentication related stuff.
mPrefs = getPreferences(MODE_PRIVATE);
String access_token = mPrefs.getString("access_token", null);
long expires = mPrefs.getLong("access_expires", 0);
if(access_token != null) {
facebook.setAccessToken(access_token);
}
if(expires != 0) {
facebook.setAccessExpires(expires);
}
/*
* Only call authorize if the access_token has expired.
*/
if(!facebook.isSessionValid()) {
facebook.authorize(Activity.this, new String[] {"publish_stream", "offline_access", "read_stream"}, new DialogListener() {
@Override
public void onComplete(Bundle values)
{
SharedPreferences.Editor editor = mPrefs.edit();
editor.putString("access_token", facebook.getAccessToken());
editor.putLong("access_expires", facebook.getAccessExpires());
editor.commit();
}
@Override
public void onFacebookError(FacebookError e) {
Log.d("FACEBOOK ERROR","FB ERROR. MSG: "+e.getMessage()+", CAUSE: "+e.getCause());
}
@Override
public void onError(DialogError e) {
Log.e("ERROR","AUTH ERROR. MSG: "+e.getMessage()+", CAUSE: "+e.getCause());
}
@Override
public void onCancel() {
Log.d("CANCELLED","AUTH CANCELLED");
}
});
}
}
@Override
public void postToWall(String data, String text, String name) {
postToFacebook(data, text, name);
}
});
dialog.dismiss();
}
}
在您的活动中添加此代码
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
facebook.authorizeCallback(requestCode, resultCode, data);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.