How To Press Back Again in to Exit in Application Android Studio Beginner Tutorials

How To Press Back Again in to Exit in Application Android Studio Beginner Tutorials



Full tutorial is given below. Dear Viewer we are working hard to maintain this website. We doesn’t want any think from you. Its just a humble request If you thinks that this posts helps you please share this post with your friends.





Activity.java

package com.usmsof.myapplication;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

public class HomeActivity extends AppCompatActivity {



    private long backpressedTime;



    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_home);
        

    }


    @Override
    public void onBackPressed() {
        if (backpressedTime+2000>System.currentTimeMillis()) {
            super.onBackPressed();
            return;
        } else {
            Toast.makeText(this,"press back again to exit", Toast.LENGTH_SHORT).show();
        }
        backpressedTime=System.currentTimeMillis();
    }

}











All Server Links to Download This File:



Previous Post
Next Post

post written by:

0 Comments: