问题
Everytime from other Activity intents to LoginActivity, it will crashes the app.
Logcat of the error:
AccessibilityManager: setStateLocked: wasEnabled = false, mIsEnabled = false, wasTouchExplorationEnabled = false, mIsTouchExplorationEnabled = false, wasHighTextContrastEnabled = false, mIsHighTextContrastEnabled = false java.lang.Throwable: setStateLocked at com.example.feoit.mapmanagement.LoginActivity.onCreate(LoginActivity.java:63)
public class LoginActivity extends AppCompatActivity implements View.OnClickListener {
EditText email, password;
Button btnSignIn, forgotpwdbtn, btnRegister;
private FirebaseAuth auth;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
email = (EditText) findViewById(R.id.email);
password = (EditText) findViewById(R.id.password);
btnSignIn = (Button) findViewById(R.id.btnSignIn);
forgotpwdbtn = (Button) findViewById(R.id.forgotpwdbtn);
btnRegister = (Button) findViewById(R.id.btnRegister);
btnSignIn.setOnClickListener(this);
forgotpwdbtn.setOnClickListener(this);
btnRegister.setOnClickListener(this);
auth = FirebaseAuth.getInstance();
}
public void onClick(View view) {
switch (view.getId()) {
case R.id.btnSignIn:
String email1 = email.getText().toString().trim();
String password1 = password.getText().toString().trim();
auth.signInWithEmailAndPassword(email1, password1).addOnCompleteListener(LoginActivity.this, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
if (task.isSuccessful()) {
Toast.makeText(LoginActivity.this, "Authentication success", Toast.LENGTH_SHORT).show();
Intent mainIntent = new Intent(LoginActivity.this, MapsTrack.class);
startActivity(mainIntent);
} else {
Toast.makeText(LoginActivity.this, "Authentication failed." + task.getException(), Toast.LENGTH_SHORT).show();
}
}
});
break;
case R.id.forgotpwdbtn:
Intent intent = new Intent(LoginActivity.this, ForgotPasswordActivity.class);
startActivity(intent);
break;
case R.id.btnRegister:
Intent intentreg = new Intent(LoginActivity.this, Register.class);
startActivity(intentreg);
break;
}
}
}
line 63 of the class is
setContentView(R.layout.activity_login);
Full logcat error:
AccessibilityManager: setStateLocked: wasEnabled = false, mIsEnabled = false, wasTouchExplorationEnabled = false, mIsTouchExplorationEnabled = false, wasHighTextContrastEnabled = false, mIsHighTextContrastEnabled = false java.lang.Throwable: setStateLocked at android.view.accessibility.AccessibilityManager.setStateLocked(AccessibilityManager.java:553) at android.view.accessibility.AccessibilityManager.tryConnectToServiceLocked(AccessibilityManager.java:636) at android.view.accessibility.AccessibilityManager.(AccessibilityManager.java:226) at android.view.accessibility.AccessibilityManager.getInstance(AccessibilityManager.java:206) at android.view.View.setFlags(View.java:9920) at android.view.ViewGroup.initViewGroup(ViewGroup.java:536) at android.view.ViewGroup.(ViewGroup.java:525) at android.view.ViewGroup.(ViewGroup.java:520) at android.view.ViewGroup.(ViewGroup.java:516) at android.view.ViewGroup.(ViewGroup.java:512) at android.widget.FrameLayout.(FrameLayout.java:119) at com.android.internal.policy.impl.PhoneWindow$DecorView.(PhoneWindow.java:2330) at com.android.internal.policy.impl.PhoneWindow.generateDecor(PhoneWindow.java:3471) at com.android.internal.policy.impl.PhoneWindow.installDecor(PhoneWindow.java:3857) at com.android.internal.policy.impl.PhoneWindow.getDecorView(PhoneWindow.java:2046) at android.support.v7.app.AppCompatDelegateImplV9.createSubDecor(AppCompatDelegateImplV9.java:367) at android.support.v7.app.AppCompatDelegateImplV9.ensureSubDecor(AppCompatDelegateImplV9.java:316) at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:281) at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140) at com.example.feoit.mapmanagement.LoginActivity.onCreate(LoginActivity.java:63) at android.app.Activity.performCreate(Activity.java:6092) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1112) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2514) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2641) at android.app.ActivityThread.access$800(ActivityThread.java:182) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1515) at android.os.Handler.dispatchMessage(Handler.java:111) at android.os.Looper.loop(Looper.java:194) at android.app.ActivityThread.main(ActivityThread.java:5717) 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:959) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:754)
回答1:
Apparently , I have found my solution. I misses a super.onStop() in an Activity, that was careless of me. Apologize and thanks for all of your times!
回答2:
It might be the way you try call intent for Login Activity from your mainActivity or where ever you try create the intent I usually use
Intent i = new Intent(this, Page2.class); // Change to LoginActivity.class
i.putExtra("isNewUser","true"); // Optional
startActivity(i);
You might be doing this already, I'm not sure as your code to call this class isn't included.
Also you should add a default case to your switch statement it could prevent tricky bugs further down the road.
来源:https://stackoverflow.com/questions/39968751/java-lang-throwable-setstatelocked