我希望实现一个简单的任务,即让用户在第一个活动上通过Facebook SSO流程,并在第二个活动上显示他们的名字。这是我的代码。
First Activity的片段(Bundle用于传递令牌)
if (access_token != null) {
facebook.setAccessToken(access_token);
Intent newPage = new Intent(
PreLogin.this, PostLogin.class);
Bundle tokenBundle = new Bundle();
tokenBundle.putString("token", facebook.getAccessToken());
newPage.putExtras(tokenBundle);
startActivity(newPage);
创建方法的第二个活动
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.postlogin);
myName = (TextView) this.findViewById(R.id.tv_name);
Bundle tokenBundle = getIntent().getExtras();
String access_token = tokenBundle.getString("token");
facebook.setAccessToken(access_token);
mAsyncRunner = new AsyncFacebookRunner(facebook);
mAsyncRunner.request("me", new IDRequestListener());
}
第二个活动IDRequestListener方法
private class IDRequestListener implements RequestListener {
@Override
public void onComplete(String response, Object state) {
try {
JSONObject json = Util.parseJson(response);
final String name = json.getString("name");
PostLogin.this.runOnUiThread(new Runnable() {
public void run() {
myName.setText("Welcome: " + name);
}
});
} catch (JSONException e) {
} catch (FacebookError e) {
}
}
@Override
public void onIOException(IOException e, Object state) {
Log.w("WARNING", "IOException");
}
@Override
public void onFileNotFoundException(FileNotFoundException e,
Object state) {
}
@Override
public void onMalformedURLException(MalformedURLException e,
Object state) {
}
@Override
public void onFacebookError(FacebookError e, Object state) {
}
}
我的textview没有被更改,当程序进入IDRequestListener方法时,它会获取我写入日志的异常。为什么不调用run()方法的任何建议?