当我在ProgressDialog
中启动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);
}
}
答案 0 :(得分:0)
你必须致电
prgDialog.dismiss();
当你想解雇它时。那么这个错误不会出现
答案 1 :(得分:0)
这会导致因为进度对话框试图将自己显示在已关闭的Activity上。
在显示对话框,进度条之前检查isFinished()
。