我正在使用 Facebook Android SDK,并希望在用户登录并获取用户对象后关闭我的 Activity。在实践中,我存储了其中的一部分,但无论如何我都想关闭该活动。
// make request to the /me API
Request.executeMeRequestAsync(session, new Request.GraphUserCallback() {
// callback after Graph API response with user object
@Override
public void onCompleted(GraphUser user, Response response) {
if (user != null) {
finish(); // causes errors
}
}
});
IDE 错误消息finish()
is: "Cannot make a static reference to the non-static method finish() from the type Activity"
如何进行?
在 onCreate 中创建对您的 Activity 的引用
//onCreate
final Activity activity = this;
然后你可以在 onCompleted 回调中使用它
activity.finish();
你可能需要做Activity activity
global.
2014 年 2 月 26 日编辑:
请注意,调用finish()
来自静态方法可能是不好的做法。你正在讲述一个具体的实例Activity
由于它有自己的生命周期,它应该从静态方法中关闭自己,没有任何生命周期或状态。理想情况下你会打电话finish()
从有约束力的东西Activity
.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)