Quick Tutorial on Android onBackPressed – Press BACK again to exit (Android Studio)

Quick Tutorial on Android onBackPressed – Press BACK again to exit (Android Studio)

Oum Saokosal

8 лет назад

33,312 Просмотров

Ссылки и html тэги не поддерживаются


Комментарии:

Viruus Red
Viruus Red - 07.03.2021 17:59

I have question. Whay when i click "yes" to close/exit, always back in before activity. And this app not close. Pls answer

Ответить
Enaam Alshawi
Enaam Alshawi - 20.04.2018 22:39

hi think you i would like to ask is there any way to do that for recent app button to or disable it >?

Ответить
BENGMUSIC
BENGMUSIC - 17.01.2018 00:29

Can you out the code link we can copy paste? You should always add the link to the code when you make videos like these 👍

Ответить
Rawezh Rasul
Rawezh Rasul - 28.12.2017 09:21

Hi. I created main activity and two other activities and created 2 buttons in main activity to go to other activities and in other activities i created one button in each activity to go back to main activity. But when i run the app. And i go to other activities and back to main activity more than one time and at the end in main activity i press back button of the emulator it go to another activities instead of exit of the app . Please can anyone help me

Ответить
Ronaldo Guedes
Ronaldo Guedes - 27.12.2017 16:44

Thanks, Very much!

Ответить
Rajesh Panchal
Rajesh Panchal - 05.12.2017 18:19

Sir how can set EXIT button in Navigation Drawer and how can work it is? Please reply

Ответить
Asmr animation creation
Asmr animation creation - 02.10.2017 05:35

thanks for this.

Ответить
Kidz Gameworld
Kidz Gameworld - 30.03.2017 10:52

Thank u very much sir

Ответить
Mohamed Ahmed
Mohamed Ahmed - 28.03.2017 23:34

I play sound in activity but when I press on back button in phone it doesn't stop , can you tell me how can I do this ?

Ответить
Kidz Gameworld
Kidz Gameworld - 27.03.2017 22:07

These videos are really helpful. thanks u sooooo much sir.

Ответить
sumsuddin midday
sumsuddin midday - 16.02.2017 22:19

The video is very helpful, Thank You so Much. God Bless You.

Ответить
Aidil Zikry
Aidil Zikry - 28.01.2017 18:45

nice tutorial, thanks sir, :D

Ответить
DESHARIO
DESHARIO - 26.12.2016 12:24

How to go back when we are on fragment !
MY CODE : (this only works on activity)
if (mDrawerLayout.isDrawerOpen(GravityCompat.START)) {
mDrawerLayout.closeDrawer(GravityCompat.START);
} else {
super.onBackPressed();
}

Fragment : .........................
Thankx a lot!

Ответить
Edgardo Zambrano
Edgardo Zambrano - 27.09.2016 07:12

Thank you, Sir.

Ответить
bashir ahmad
bashir ahmad - 25.07.2016 07:51

nice explain. thanks for help

Ответить
Stav Raviv
Stav Raviv - 17.07.2016 15:34

It might be easier to implement this without a Handler if you just save the timestamp of the last click and compare it on each click. something like
private long lastClick;
public void onBackPressed() {
long now = System.currentTimeMillis();
if (now - lastClick < 3000) {
super.onBackPressed();
} else {
Toast...show() ;
lastClick = now;
}
}

Ответить
alvaro jose nogales sangally
alvaro jose nogales sangally - 08.05.2016 22:17

thank you very much...........

Ответить