Currently, I am working on my first Android application in Android Studio Code. The app consists of multiple activities. It is working beautifully on my virtual device, but the app crashes on my device when I am starting a third activity in a second activity. Thus, it is possible to go from the main activity to the second without problems.
Below you can see my class. It is important to note that, when I am running the app, I can see the toast message after the if-statement (encryptedPassword.equals(storedPassword)). After that, the app crashes. I don't see any errors. Moreover, I cannot catch the exception due the fact the app crashes before that point, obviously.
public class LoginActivity extends AppCompatActivity {
private String errorLogin;
private String wrongPassword;
private String rightPassword;
private String tryAgain;
private String greeting;
private static final String PACKAGE_NAME = "nl.test.notevault.activities";
private static final String NOTES_ACTIVITY = "NotesActivity";
Button loginButton;
EditText loginPassword;
Context context;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
loginButton = (Button)findViewById(R.id.loginButton);
loginPassword = (EditText)findViewById(R.id.loginPassword);
context = this;
errorLogin = getString(R.string.error_login_general);
wrongPassword = getString(R.string.error_login_wrong_password);
rightPassword = getString(R.string.success_login_general);
tryAgain = getString(R.string.action_try_again);
greeting = getString(R.string.greeting_general);
loginButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
try {
EncryptString e = new EncryptString();
String encryptedPassword = e.encrypt(loginPassword.getText().toString());
KeyValueDB k = new KeyValueDB();
String storedPassword = k.getPassword(context);
if (encryptedPassword.equals(storedPassword)) {
Toast.makeText(getApplicationContext(), rightPassword + ". " + greeting + ", " + k.getUsername(context) + "!", Toast.LENGTH_SHORT).show();
Intent intent = new Intent(LoginActivity.this, NotesActivity.class);
startActivity(intent);
} else {
Toast.makeText(getApplicationContext(), wrongPassword + ". " + tryAgain + ".", Toast.LENGTH_SHORT).show();
loginPassword.setText(null);
}
} catch (Exception e) {
Toast.makeText(getApplicationContext(), errorLogin + ".", Toast.LENGTH_SHORT).show();
}
}
});
It might be possible that something is wrong with my manifest. Below you can see it. All activities are stored in a activities package.
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".activities.MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".activities.LoginActivity"
android:label="@string/title_activity_login" />
<activity
android:name=".activities.SetupActivity"
android:label="@string/title_activity_setup" />
<activity android:name=".activities.CreateNoteActivity" />
<activity android:name=".activities.NotesActivity"
android:label="Notes" />
<activity android:name=".activities.EditNoteActivity" />
<activity android:name=".activities.SettingsActivity"></activity>
</application>
The logcat output of the virtual device. Please note that the app is working fine on the virtual device. I cannot connect my phone to my computer due the fact I don't have the right connector atm.
W/System: ClassLoader referenced unknown path: /data/app/nl.test.notevault-2/lib/x86
I/InstantRun: Instant Run Runtime started. Android package is nl.test.notevault, real application class is null.
W/System: ClassLoader referenced unknown path: /data/app/nl.test.notevault-2/lib/x86
W/art: Before Android 4.1, method android.graphics.PorterDuffColorFilter android.support.graphics.drawable.VectorDrawableCompat.updateTintFilter(android.graphics.PorterDuffColorFilter, android.content.res.ColorStateList, android.graphics.PorterDuff$Mode) would have incorrectly overridden the package-private method in android.graphics.drawable.Drawable
I/OpenGLRenderer: Initialized EGL, version 1.4
D/OpenGLRenderer: Swap behavior 1
E/EGL_emulation: tid 3721: eglSurfaceAttrib(1174): error 0x3009 (EGL_BAD_MATCH)
W/OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0xaefc9e60, error=EGL_BAD_MATCH
W/IInputConnectionWrapper: finishComposingText on inactive InputConnection
E/EGL_emulation: tid 3721: eglSurfaceAttrib(1174): error 0x3009 (EGL_BAD_MATCH)
W/OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0x92ab8ac0, error=EGL_BAD_MATCH
E/EGL_emulation: tid 3721: eglSurfaceAttrib(1174): error 0x3009 (EGL_BAD_MATCH)
W/OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0xaefd0280, error=EGL_BAD_MATCH
W/IInputConnectionWrapper: finishComposingText on inactive InputConnection
W/IInputConnectionWrapper: finishComposingText on inactive InputConnection
W/IInputConnectionWrapper: finishComposingText on inactive InputConnection
E/EGL_emulation: tid 3721: eglSurfaceAttrib(1174): error 0x3009 (EGL_BAD_MATCH)
W/OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0x92ab9680, error=EGL_BAD_MATCH
E/EGL_emulation: tid 3721: eglSurfaceAttrib(1174): error 0x3009 (EGL_BAD_MATCH)
W/OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0xaefc9e40, error=EGL_BAD_MATCH
W/IInputConnectionWrapper: finishComposingText on inactive InputConnection
W/IInputConnectionWrapper: finishComposingText on inactive InputConnection