Here is my scenario: I have a series of Activity
. I set a timeout on those Activity
that will disconnect the user in case it get inactive for a moment. But I want to redirect the user to its last screen in case he log
When I'm disconnecting the user I'm calling this:
public void restartFromLoginActivity(boolean saveCurrentState, String previousLoggedUserId) {
Activity currentActivity = getCurrentActivity();
Intent intent = new Intent(CERHISApplication.this, LoginActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
if(saveCurrentState && currentActivity != null){
Bundle extras = new Bundle();
extras.putString(ApplicationController.KEY_PREVIOUSLY_LOGGED_USER_ID, previousLoggedUserId);
intent.putExtras(extras);
currentActivity.startActivityForResult(intent, ApplicationController.RC_LOGIN);
}
else
startActivity(intent);
if(currentActivity != null)
currentActivity.finish();
}
And in my LoginActivity
I check if the userId is the same, if so I try to call redirect the user via onActivityResult
like this:
if (getCallingActivity() != null && userId.equals(previouslyLoggedUserId))
setResult(RESULT_OK);
else
ApplicationController.startHomeActivity(this);
But this doesn't work because I set the flag FLAG_ACTIVITY_NEW_TASK
to my intent. As said in the documentation:
This flag can not be used when the caller is requesting a result from the activity being launched.
Which I understand, an Activity
can only receive results from an Activity
from the task. But I need to set this flag otherwise the user would be able to get back in the Activity stack
by pressing the back button.
Is their any workaround to combine both the clearing of the stack to avoid the user to get back Activities before he logs in again and the redirect behavior I would like to introduce?
Any idea is welcome, thanks.