我使用以下方法来分享我的应用数据 但如果用户点击主屏幕,我希望它强行关闭facebook连接。
public class FacebookIntegration {
private static User user;
private static String NEXT_URL = "http://www.facebook.com/connect/login_success.html";
private static String APPLICATION_ID ;
private static String APPLICATION_SECRET ;
private static String[] PERMISSIONS = Facebook.Permissions.USER_DATA_PERMISSIONS;
public static boolean posted = false;
private static String[] postPermissions = Facebook.Permissions.PUBLISHING_PERMISSIONS;
private static SharePopup _obj;
private static boolean exception = false;
public static boolean integrate(SharePopup obj) {
_obj = obj;
ApplicationSettings as = new ApplicationSettings(NEXT_URL, APPLICATION_ID, APPLICATION_SECRET, PERMISSIONS);
ApplicationSettings as2 = new ApplicationSettings(null, APPLICATION_ID, APPLICATION_SECRET, PERMISSIONS);
Facebook fb = Facebook.getInstance(as);
_obj.close();
try {
user = fb.getCurrentUser();
} catch (FacebookException e1) {
e1.printStackTrace();
exception = true;
}
if (!exception) {
try {
fb.getCurrentUser(new BasicAsyncCallback() {
public void onComplete(com.blackberry.facebook.inf.Object[] objects, final java.lang.Object state) {
FacebookIntegration.this.user = (User) objects[0];
Vector prayerTimes = (Vector) PrayerTimesDTO.getPrayerTimes();
StringBuffer post = new StringBuffer("avbc");
user.publishStatus(post.toString());
posted = true;
user.publishPost("stream.publish", "published through the Facebook API", APPLICATION_SECRET, null, null, null, user.getId());
}
public void onException(final Exception e, final java.lang.Object state) {
e.printStackTrace();
}
});
} catch (FacebookException e) {
e.printStackTrace();
} finally {
fb.logout(true);
}
}
return true;
}
}
答案 0 :(得分:0)
自从你第一次发布以来,我一直在思考这个问题。我认为没有人可以帮助你,因为我们必须知道Facebook对象的作用。很可能你必须关闭连接。
答案 1 :(得分:0)
一个。在MainScreen类中重写onClose函数:
public boolean onClose() {
FacebookIntegration.closeConnection();
return super.onClose();
}
B.如下更改FacebookIntegration
:
将Facebook对象作为静态字段放在班级
中 private static Facebook fb;
更改以下行:Facebook fb = Facebook.getInstance(as);
是fb = Facebook.getInstance(as);
将closeConnection
方法添加到FacebookIntegration
,如下所示:
public static void closeConnection() {
fb.logout(true);
}