A
A
AlexAlex0002021-04-13 19:46:00
Java
AlexAlex000, 2021-04-13 19:46:00

How to override back button press in application?

Bottom line: I have an application that works in one activity and without fragments. The entire interface is drawn programmatically, control is done using the TouchListener, switching between application screens is done by replacing View in Layout.
Now, when I press the hardware Back button, I simply close the only Activity and, accordingly, the application, is it possible to override the purpose of the back button, so that, for example, when it is pressed, the current View is replaced with the main one (which opens when the application starts), and if the main View is launched, closed applications occur ?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Denis Zagaevsky, 2021-04-13
@AlexAlex000

Yes, you can, onBackPressed for the activity. But in general, this is all a so-so idea.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question