03-02 12:47:02.785 9439-9439/com.ucu.ccs.classrecord
E/WindowManager﹕ android.view.WindowLeaked: Activity
com.ucu.ccs.classrecord.Login has leaked window
com.android.internal.policy.impl.PhoneWindow$DecorView{6d17cc4
V.E….. R……D 0,0-1002,348} that was originally added here
at android.view.ViewRootImpl.(ViewRootImpl.java:465)
at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:277)
at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:69)
at android.app.Dialog.show(Dialog.java:312)
at com.ucu.ccs.classrecord.Login$AttemptLogin.onPreExecute(Login.java:158)
at android.os.AsyncTask.executeOnExecutor(AsyncTask.java:587)
at android.os.AsyncTask.execute(AsyncTask.java:535)
at com.ucu.ccs.classrecord.Login.isOnline(Login.java:113)
at com.ucu.ccs.classrecord.Login$1.onClick(Login.java:73)
at android.view.View.performClick(View.java:5197)
at android.view.View$PerformClick.run(View.java:20926)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:5942)
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:1399)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194)
这是我的代码:
buttonLogin.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { String instructor_id = editUser.getText().toString().trim(); String password = editPass.getText().toString().trim(); SharedPreferences preferences = getSharedPreferences("MyApp",MODE_PRIVATE); preferences.edit().putString("password",password).commit(); preferences.edit().putString("inst_id",instructor_id).commit(); if (editUser.getText().toString().equals("") || editPass.getText().toString().equals("")){ Toast.makeText(getApplicationContext(),"Please enter Instructor ID and Password",Toast.LENGTH_LONG).show(); }else { isOnline(); } } }); public boolean isOnline(){ ConnectivityManager connectivityManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo(); if (networkInfo != null && networkInfo.isConnectedOrConnecting()){ new AttemptLogin().execute(); }else { checkInternet(); } return false; } class AttemptLogin extends AsyncTask<String,String,String> { boolean failure = false; String inst_id = editUser.getText().toString(); String password = editPass.getText().toString(); @Override protected void onPreExecute() { super.onPreExecute(); pDialog = new ProgressDialog(Login.this); pDialog.setMessage("Attempting login..."); pDialog.setIndeterminate(false); pDialog.setCancelable(true); pDialog.show(); } @Override protected String doInBackground(String... params) { int success; try{ List<NameValuePair> mList = new ArrayList<NameValuePair>(); mList.add(new BasicNameValuePair("instructor_id",inst_id)); mList.add(new BasicNameValuePair("password",password)); Log.d("request!","starting"); JSONObject json = jsonParser.makeHttpRequest(LOGIN_URL,"POST",mList); Log.d("Login attempt",json.toString()); success = json.getInt(TAG_SUCCESS); if (success == 1) { Log.d("Login Successful!",json.toString()); Intent i = new Intent(Login.this,MainActivity.class); startActivity(i); //finish(); return json.getString(TAG_MESSAGE); }else{ Log.d("Login Failure!",json.getString(TAG_MESSAGE)); return json.getString(TAG_MESSAGE); } }catch (JSONException e){ e.printStackTrace(); } return null; } @Override protected void onPostExecute(String s) { super.onPostExecute(s); session.setLogin(true); pDialog.dismiss(); if (s != null){ Toast.makeText(getApplicationContext(),s,Toast.LENGTH_SHORT).show(); } } }