Close activity hierarchy in Android -


How can I turn off a whole hierarchy of activities and can not present a new activity in the current job?

Context

Consider an FTP browser that restarts the last session on the launch. Each folder is displayed in your activity. When I click on a folder, a new activity is started for the folder. If I press the back button, the app comes back to the previous activity, which matches the original folder.

I can logoff from the menu at any time. Logging off will bring me login activity (the app has resumed the session when the current task is not present), and stop all other activities How can I do this?

What I have read, if the activity was in the current job, then I can use the FLAG_ACTIVITY_CLEAR_TOP , but this is not my case.

An approach startActivityForResult can be used. For example, your first activity is log-in activity. And if there is folder activity in it then the flow will be - 1 login activity (launcher activity)
2. folder activity (root as folder)
3. folder activation (folder contents have been clicked on ) ... and so on
Now start any new folder activity Use startAcitivityForResult for the field. Former> extends the login activity activity of the public class {onCreate () {} onLogin () {startActivityForResult (intent, 100 / * some request code * /); // Start folder activity, override onactive result (intrate codecode, inc. Result, result, intent of intention) {if (requestcode == 100 & amp; amp; result code == LOGOFF_ACTION) {// sign out and login screen Show}}

expansion on public class folder activity activity (onCreate) {} onClickOnSomeFolder () {startActivityForResult (with folder details etc / intentions / * etc, / 100); } @ Override OnActivity Result (result code of Int octcode, int) {if (Requestcode == 100 & amp; amp; amp; result code == LOGOFF_ACTION) {setResult (resultcode, intent); End(); } And if (requestcode + = 100 & amp; resultcode == backbutton) {/ * No need to end this activity} />} backbutton () {setResult (BACK_BUTTON, intent); End(); } OnLogOff () {setResult (LOGOFF_ACTION, Intent); End(); }} So now if the user chooses to sign up using the menu, the activities will start until the order starts in the same order until it reaches LoginActivity.


Comments