Here are some possible workarounds.
Option 1:
An option might be to keep an ActivityStateManager.xml file saved in you app folder, which you will read when starting app. In this xml file you could keep a basic property StartLoginAcivity = true/false.
Create a MainActivity which will be extended by all our activities, except B,C,D and override the home button and set StartLoginAcivity property in ActivityStateManager.xml to false.
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if ((keyCode == KeyEvent.KEYCODE_HOME)) {
// set StartLoginAcivity property in ActivityStateManager.xml to true
return false;
}
return super.onKeyDown(keyCode, event);
}
Override the home button in activities B, C, D (or in a RequireLoginActivity which will be extended by these activities), and set StartLoginAcivity property in ActivityStateManager.xml to true.
When starting the app, read ActivityStateManager.xml and if StartLoginAcivity = true, open LoginActivity.
Option 2:
Override the home button in activities B, C, D (or in a RequireLoginActivity which will be extended by these activities), and force close app like
How to close an android application?. When starting app, it will open your default main activity
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if ((keyCode == KeyEvent.KEYCODE_HOME)) {
// force close app
Intent homeIntent = new Intent(Intent.ACTION_MAIN);
homeIntent.addCategory( Intent.CATEGORY_HOME );
homeIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(homeIntent);
}
return true;
//return super.onKeyDown(keyCode, event);
}