Reputation: 982
I have the following code which is executed once the user clicks a button
public void logout(){
// redirect user back to login screen activity
Intent i = new Intent(this, LoginActivity.class);
// Closing all the Activities
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
// Add new Flag to start new Activity
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
// start Login Activity
startActivity(i);
}
However each time the button is clicked, the emulator crashes. Any ideas what i might be doing wrong?
Upvotes: 0
Views: 116
Reputation: 982
The issue was prior to this method being called. I was trying to set the text on an EditText item that was part of another layout
Upvotes: 0
Reputation: 5266
You can set flags instead by doing
i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK));
I doubt this is your issue though, make sure you are calling startActivity
from within the Activity and the correct Thread
, and make sure there are no issues with the onCreate
of your LoginActivity
.
Is this consistent with more than one emulator? Try a different configuration, and also check your AndroidManifest.xml
file, is the second Activity
defined?
Upvotes: 1