我希望在用户登录时显示进度对话框... 我有不同的解决方案,但仍然告诉我dis 错误
WindowManager:android.view.WindowLeaked:Activity com.example.mariamhp.inicrepot.login泄露了窗口com.android.internal.policy.impl.PhoneWindow $ DecorView {1ebb896b VE .... R .....最初添加的.D 0,0-729,322}
bLogin.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final String username = etUsername.getText().toString();
final String password = etPassword.getText().toString();
if(username.length()==0){
etUsername.requestFocus();
etUsername.setError("FIELD CANNOT BE EMPTY");
}
else if(!username.matches("[0-1a-zA-Z]+"))
{
etUsername.requestFocus();
etUsername.setError("ENTER ONLY ALPHANUMIRIC CHARACTER");
}
else if(password.length()==0)
{
etPassword.requestFocus();
etPassword.setError("FIELD CANNOT BE EMPTY");
}else {
final ProgressDialog progresRing = ProgressDialog.show(login.this, "Login in", "Please Wait...", true);
progresRing.setCancelable(true);
new Thread(new Runnable() {
@Override
public void run() {
try {
Thread.sleep(100);
} catch (InterruptedException ignored) {
progresRing.dismiss();
}
}
}).start();
}
// Response received from the server
Response.Listener<String> responseListener = new Response.Listener<String>() {
@Override
public void onResponse(String response) {
try {
JSONObject jsonResponse = new JSONObject(response);
boolean success = jsonResponse.getBoolean("success");
if (success) {
Intent intent = new Intent(login.this, user_area.class);
login.this.startActivity(intent);
finish();
} else {
AlertDialog.Builder builder = new AlertDialog.Builder(login.this);
builder.setMessage("Login Failed")
.setNegativeButton("Retry", null)
.create()
.show();
}
} catch (JSONException e) {
e.printStackTrace();
}
}
};
LoginRequest loginRequest = new LoginRequest(username, password, responseListener);
RequestQueue queue = Volley.newRequestQueue(login.this);
queue.add(loginRequest);
}
}
);
}
@Override
public void onStop() {
super.onStop();
if (progresRing != null) {
progresRing.dismiss();
progresRing = null;
}
}
}
请任何可能的解决方案......这是我的logcat
E/WindowManager: android.view.WindowLeaked: Activity com.example.mariamhp.inicrepot.login has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView{1ebb896b V.E..... R......D 0,0-729,322} that was originally added here
at android.view.ViewRootImpl.<init>(ViewRootImpl.java:363)
at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:271)
at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:85)
at android.app.Dialog.show(Dialog.java:298)
at android.app.ProgressDialog.show(ProgressDialog.java:116)
at android.app.ProgressDialog.show(ProgressDialog.java:99)
at com.example.mariamhp.inicrepot.login$2.onClick(login.java:64)
at android.view.View.performClick(View.java:4780)
at android.view.View$PerformClick.run(View.java:19866)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5254)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
答案 0 :(得分:0)
在进入下一个活动之前,您应该关闭进度条。
因此,在调用下一个活动之前,请忽略进度条。
// Here dismiss the progress bar
Intent intent = new Intent(login.this, user_area.class);
login.this.startActivity(intent);
finish();