当我ProgressDialog
在我的 中启动 a 时Activity
,一切正常。在我按下对话框上的后退按钮以恢复后Activity
,我收到一个错误:“无法添加窗口令牌 android.BindeProxy@b6483550 无效,您的活动是否正在运行?”。有没有办法ProgressDialog
在我想完成它时关闭Activity
它,然后在我下次启动它时再次显示它Activity
?
我的代码:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mFacebook = new Facebook(APP_ID);
mAsyncRunner = new AsyncFacebookRunner(mFacebook);
SessionStore.restore(mFacebook, this);
setContentView(R.layout.login_view);
mLoginButton = (LoginButton) findViewById(R.id.login);
SessionEvents.addAuthListener(new SampleAuthListener());
mLoginButton.init(this, mFacebook);
}
@Override
public void onResume () {
super.onResume();
}
@Override
public void onPause () {
super.onPause();
}
public class SampleAuthListener implements AuthListener {
public void onAuthSucceed() {
TheGaffer.this.progressDialog = ProgressDialog.show(TheGaffer.this, "Loading", "Please wait...");
Bundle params = new Bundle();
params.putString("fields", "name,id");
mAsyncRunner.request("me", params, new LoginRequestListener());
}
public void onAuthFail(String error) {
Toast.makeText(getApplicationContext(), error,
Toast.LENGTH_LONG).show();
}
}
public class LoginRequestListener implements RequestListener {
public void onComplete(final String response, final Object state) {
try {
JSONObject jsonObjSend = new JSONObject();
JSONObject json = Util.parseJson(response);
final String fbid = json.getString("id");
jsonObjSend.put("fbid", json.getString("id"));
jsonObjSend.put("username", json.getString("name"));
jsonObjSend.put("playerPhoto", "http://graph.facebook.com/"+ json.getString("id") +"/picture");
HttpClient.SendHttpPost("/user_profiles/registerUser", jsonObjSend);
TheGaffer.this.runOnUiThread(new Runnable() {
public void run() {
if (TheGaffer.this.progressDialog != null) {
TheGaffer.this.progressDialog.dismiss();
}
Intent intent = new Intent(TheGaffer.this, TeamActivity.class);
intent.putExtra("fbid", fbid);
startActivity(intent);
}
});
} catch (JSONException e) {
Log.w("Facebook-Example", "JSON Error in response");
} catch (FacebookError e) {
Log.w("Facebook-Example", "Facebook Error: " + e.getMessage());
}
}
public void onFacebookError(FacebookError e, final Object state) {
Log.e("Facebook", e.getMessage());
e.printStackTrace();
}
public void onFileNotFoundException(FileNotFoundException e,
final Object state) {
Log.e("Facebook", e.getMessage());
e.printStackTrace();
}
public void onIOException(IOException e, final Object state) {
Log.e("Facebook", e.getMessage());
e.printStackTrace();
}
public void onMalformedURLException(MalformedURLException e,
final Object state) {
Log.e("Facebook", e.getMessage());
e.printStackTrace();
}
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event)
{
if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0)
{
TheGaffer.this.progressDialog = null;
finish();
return true;
}
return super.onKeyDown(keyCode, event);
}
}