Clearing an activity stack via Intent
is well documented with questions like this.
However this solution assumes that you are moving from one activity to another. Is there a way to clear this stack programmatically without having to start a new activity using an Intent
?
To put this question in context:
My app has a database that synchronizes with a master online database. However the app needs to be available offline, so it has a completely replicated database stored locally in SQLite
. I have an activity called FullSyncActivity
which basically has a button called Start Sync
. When the button is pressed, the sync starts (clears existing data and re-downloads from the server) and once the sync is complete, a new activity starts again.
The problem I have is that the user might navigate to the FullSyncActivity
without fully understanding it's purpose - hence why I do not want to start the sync process when the activity opens (a Start Sync
button is required). However, I cannot clear the activity stack when the activity is started (using an intent), because if the user cancels without pressing the Start Sync
button, then they will have nowhere to return to. Ideally I'd like to clear the activity stack once the user presses the button. Is this possible?