Why doesn't the activity end or get destroyed after calling finish () on onBackPressed ()?

Friends In my activity, I placed finish() inside onBackpressed() , but sometimes it does not end or does not destroy the activity. What is the problem?

+4
source share
4 answers

super.onBackpressed() will do the finishing thing for you, so do not comment on this line after overriding this function .. add additional functions to this function if you have ...

+5
source

finish () just tells the activity to do what it needs to complete, for example. shutdown, call onPause, report result for parent, etc. It does not make an exit () call or anything else.

You must return after calling finish ().

also see this question: about finish () in android

+1
source

you can also use finish (); inside onBackPressed ();

try it...

0
source

Sometimes the finish () method is not supported. your OnBackPressed () method should have @Override notation. bt this designation is only supported at API levels greater than 5.

it works for me.

-one
source

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


All Articles