Do you always call finish()
on some activity before going to another activity?
For example, in order to prevent user going to the previous activity via mobile back button, some people suggest that you should finish all activities, except the main one. This way, the back button always returns you to the main activity (or any other activity you think a user should be navigated). This is done by overriding back button behaviour.
Bad thing of this is when there is a dialog run from the Handler which try to runs after the activity finished (http://dimitar.me/android-displaying-dialogs-from-background-threads/).
What is your rule of thumb on this issue? Call finish()
in some smarter way or overriding back button to direct user to page of your choice?
When the user is on Activity D and click a button called exit, the application should go back to Activity B and finish the Activities C and D.
On Clicking the back button from the New Activity, the finish() method is called and the activity destroys and returns to the home screen.
Say finish(); Like this you can call Activity's finish method from another class. It is perfectly working.
If you understood the workflow of an Android application, there should be no need to override the back-button (except for some special cases like Games for example).
If you don't want the user to get back to the previous Activity, finish it. There should be no need to override the back-button for that.
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();
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With