I Have 2 activities in my app - Welcome, Login. The app starts with the Welcome activity, then finishes it and starts the Login activity:
public void onAnimationEnd(Animation animation)
{
Intent i = new Intent(Welcome.this, Login.class);
i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(i);
finish();
}
I've also override the onBackPressed
function:
public void onBackPressed()
{
Intent a = new Intent(Intent.ACTION_MAIN);
a.addCategory(Intent.CATEGORY_HOME);
startActivity(a);
}
But when I try to click the back button on the Login activity (as shown here) nothing happens.
I want the app to close and return to the previous app when i click the back button.
Thanks Ahead,
Amit
The arrow on the toolbar is not a "back button", but an "up button" and should, at least in theory, behave different from the device's back button (see docs).
If you want it to behave like a back button, you can manually wire it to do that:
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == android.R.id.home) {
onBackPressed();
return true;
}
return super.onOptionsItemSelected(item);
}
If you want your app to disappear to the background, there is no need for you to override onBackPressed()
and manually launch in intent for the homescreen as you did, given there is no backstack of activities, i.e. no activity "behind" your LoginActivity
.