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

Quick Tutorial on Android onBackPressed – Press BACK again to exit (Android Studio) - Hello friends Android tutorial and tips trik, The article you are reading this time with the title Quick Tutorial on Android onBackPressed – Press BACK again to exit (Android Studio), we have prepared this article for you to read and download the information therein. hopefully fill posts article –, article again, article android, article BACK, article exit, article on, article onBackPressed, article Press, article Quick, article Studio, article TO, article Tutorial, we can write this you understand. Well, happy reading.

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

Baca juga


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

Hello everyone! My name is Oum Saokosal Today I want to make a short video about AndroidonBackPressed.

I will do like, please press back again toexit.

So this concept is very useful.

You can be when your user from exit accidentally,you know, like usually, they press back and then they just exit it.

So we want to prevent them and ask them topress that twice.

So let's go to Android.

For that you don't need any special permissionto do that and we don't need any of you here so just go to MainActivity.

Java file and whatyou have to do down here, you go to code menu and then Override method and then you canfind onBackPress under the android support version four.

So it just means that it happened very longtime ago.

So this is the even and we will call super.

Super is the activity so if you have thisline of code it will exit.

So, left Tab here and I use Genymotion formy emulator.

Ok! In your emulator just click on back and itwill exit but if you commanded it means that this gonna stay there.

It won't let you exit the app.

Ok! First one again see.

It you will not let you go out from this app.

So now, we don't want to exit, you know like,suddenly and you can have Toast.

Ok! You can say something like, "Please press BACK again to exit" And maybe a short length is ok and it willshow this message when they try to click on the back button and now it's a trick.

So, if we do like this it means that our applicationwill not let user exit from us and the user will be angry.

What you have to do is to call a "thread" to delaythe accident.

So, you can call, new Handler() But there are two handlers.

One is the Java Util logging and one thatwe want to use, it's android OS.

So, I think we have to import it manually.

Over here, Import android.

Os.

Handler This is the right one.

Otherwise, it will not let you use the handler,the real handler here and we want to delay it.

So, we call postDelayed and the action there,is going to be a threat and in Java that is in the running for class.

So, you call new Runnable like this and click.

And the second parameter is, the second.

Maybe, three seconds.

Ok! And the three-second you say something.

Ok! So, now we want to say that, If button islike a quick price, you know, and then you follow Boolean.

Just call twice here and even twice then you'regonna exit.

Ok! But around here, you're going to hold thebutton is like, if you press and then it will delay a little bit slower and you call twicehere and you sign to false and after that, you will sign back to True.

Ok! And if the button is true, if the twice istrue, then you want to exit from the app.

So, to safely exit from the app you need thiscode.

it's a lot of code but we will make sure thatyour app will exit without any problem.

Ok! So, let's put the lock here and you will understand.

Let me get it.

So I want to get a name from that.

It's easy to use the code like this.

Over here, maybe TAG and say, click and overhere you can do the lock twice but it isn't true and false but the quality the booleanspring and maybe around here twice again and you will see.

Maybe I put it, maybe over here.

Again if you click it, it will delay a littlebit for three second and you click it again, it won't happen.

Now, let's see the lock in.

So, let's move it over here.

When I click it, it true but three seconds,later it becomes false.

So, if you click it and then you click itagain, so the first time you click it, it's going to turn twice to true.

The reason for that is that boolean the defaultvalue is false, you don't know that maybe it's ____ and it's better if you don't knowit like, this twice false.

So, like the false here, come in and we'llcheck it twice true.

It gonna exit but it's not, it's just falseand then it's gonna turn it twice to true and then three seconds later it's gonna turnit to false again.

So if you don't press it during the threeseconds and then it gonna turn to false.

So, that's it that's the end of the video.

If you like it, please subscribe and I willsee you in the next video.

Thank you!.



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

That article Quick Tutorial on Android onBackPressed – Press BACK again to exit (Android Studio) This time, hopefully we can give you all of the benefits. Well, I'll see you in another article post.

You now read the article Quick Tutorial on Android onBackPressed – Press BACK again to exit (Android Studio) the link address http://svedda79.blogspot.com/2016/11/quick-tutorial-on-android-onbackpressed.html

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

Post a Comment