androidandroid-strictmode

how to know violation in strict mode


i am sending login request to web service and i have enabled strict mode and getting following error

03-05 16:54:36.490: E/AndroidRuntime(1106): FATAL EXCEPTION: main
03-05 16:54:36.490: E/AndroidRuntime(1106):    android.os.StrictMode$StrictModeViolation:      policy=95 violation=2
03-05 16:54:36.490: E/AndroidRuntime(1106):     at    android.os.StrictMode.executeDeathPenalty(StrictMode.java:1311)
03-05 16:54:36.490: E/AndroidRuntime(1106):     at android.os.StrictMode.access$1300(StrictMode.java:112)
03-05 16:54:36.490: E/AndroidRuntime(1106):     at android.os.StrictMode$AndroidBlockGuardPolicy.handleViolation(StrictMode.java:1304)
03-05 16:54:36.490: E/AndroidRuntime(1106):     at android.os.StrictMode$AndroidBlockGuardPolicy$1.run(StrictMode.java:1191)
03-05 16:54:36.490: E/AndroidRuntime(1106):     at andro

how to get what is violated here.

public class LoginActivity extends Activity implements ILoginDelegate {

// Values for email and password at the time of the login attempt.
private String mEmail;
private String mPassword;


@Override
protected void onCreate(Bundle savedInstanceState) {

            StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
            .detectAll().penaltyLog().penaltyDeath().build());

     //             StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder().detectAll()
   //                       .penaltyLog().penaltyDeath().build());

    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_login);

    findViewById(R.id.sign_in_button).setOnClickListener(
            new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    attemptLogin();
                }

            });
}

public void attemptLogin() {

        // Send login requesmEmail
        try {
            LoginManager manager = new LoginManager(this);
            manager.sendLoginRequest(mEmail, mPassword);
        } catch(Exception e) {
              e.printStackTrace();

        }       

    }

here is updated code. Please suggest where i am doing wrong

thanks


Solution

  • Keeping disk and network operations off the main thread makes for much smoother, more responsive applications.

    Above quote is from: StrictMode documentation

    Network Operation should not be done on UI thread.Recommended to use AsyncTask /Run a thread.This Will solve your problem