[英]Android ProgressDialog Error When Resuming an Activity
When I start a ProgressDialog
in my Activity
, everything works correctly. 当我在
Activity
启动ProgressDialog
时,一切正常。 After I press the back button on the dialog to resume the Activity
, I receive an error: "Unable to add window token android.BindeProxy@b6483550 is not valid, is your activity running?". 在按下对话框上的“后退”按钮以恢复“
Activity
,我收到一条错误消息:“无法添加窗口令牌android.BindeProxy@b6483550无效,您的活动正在运行吗?”。 Is there a way to close the ProgressDialog
when I want to finish this Activity
and then show it again next time I start this Activity
? 当我想完成此
Activity
并在下次启动此Activity
时再次显示它时,是否可以关闭ProgressDialog
?
My Code: 我的代码:
@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);
}
} }
You have to call 你必须打电话
prgDialog.dismiss(); prgDialog.dismiss();
when you want to dismiss it. 当您想关闭它时。 Then this error will not be there
那么这个错误就不会出现
It causes because progress dialog tried to show itself on to an Activity which has already been closed. 这是因为进度对话框试图将自己显示在已关闭的活动上。 Check for
isFinished()
before you show a dialog, progress bar. 在显示对话框,进度条之前,请检查
isFinished()
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.