Do I always have to finish one activity before moving on to another?

Do you always call finish() for some activity before moving on to another action?

For example, so that the user does not go to the previous action using the "Back" button, some people suggest completing all the actions except the main one. Thus, the back button always returns you to the main action (or to any other action that, in your opinion, should be used to navigate the user). This is done by overriding the behavior of the button.

This happens quite well when a dialog is launched from the handler that tries to start after the action is completed (http://dimitar.me/android-displaying-dialogs-from-background-threads/).

What is your rule of thumb on this issue? Call finish() some smarter way or by canceling the return button to direct the user to the page of your choice?

+6
source share
3 answers

If you understand the workflow of an Android app, you don’t need to redefine the back button (except for some special cases, such as games).

If you do not want the user to return to the previous action, complete it. You do not need to redefine the back button for this.

 public class Activity1 extends Activity{ // Some onclick-Handler public void onButtonClick(View v){ Intent i = new Intent(this, Activity2.class); this.startActivity(i); // Don't want you to return: this.finish(); } } 
+4
source

If you don’t want the Back button to go to the current action, click the “complete” action.

If you have a dialog box open, override the onPause activity method and close the dialog. onPause will be called when activity goes to the screen.

We only redefine the onBackPressed method, when we need to do something in normal cases, we just leave it.

+1
source

If you want to open another action and want to complete the previous operation, use the final (); after calling the intent of another action.

he will complete the current activity and open a new activity.

0
source

Source: https://habr.com/ru/post/900586/


All Articles