我已通过Strava授权我的应用,我想从中获取令牌。问题在于此代码中
LoginResult result = api.getTokenForApp(AppCredentials.with(29519, "8d55af50a97a9f4b5269670de00bf5e6f4b9942d "))
.withCode(code)
.execute();
我认为它永远不会运行,因为我看不到test5打印出来。它直接进入线程外的意图。另外我怎么能从 LoginResult 获得结果 >在我的线程和类之外使用它?
代码如下:
@Override
protected void onActivityResult(int requestCode, int resultCode, final Intent data) {
super.onActivityResult(requestCode, resultCode, data);
Log.d("Strava code", "TEST1");
if(requestCode == RQ_LOGIN && resultCode == RESULT_OK && data != null) {
Thread thread = new Thread(new Runnable() {
@Override
public void run() {
try {
String code = data.getStringExtra(StravaLoginActivity.RESULT_CODE);
Log.d("Strava code", "TEST2");
AuthenticationConfig config = AuthenticationConfig.create()
.debug()
.build();
Log.d("Strava code", "TEST3");
AuthenticationAPI api = new AuthenticationAPI(config);
Log.d("Strava code", "TEST4");
LoginResult result = api.getTokenForApp(AppCredentials.with(29519, "8d55af50a97a9f4b5269670de00bf5e6f4b9942d "))
.withCode(code)
.execute();
Log.d("Strava code", "TEST5");
} catch (Exception e) {
e.printStackTrace();
}
}
});
thread.start();
Intent testInt= new Intent(MainActivity.this,TestActivity.class);
startActivity(testInt);
}