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.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import android.content.DialogInterface;
import android.os.Bundle;
public class HomeActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home);
}
@Override
public void onBackPressed() {
new AlertDialog.Builder(this)
.setTitle("Exit")
.setMessage("Are you sure you want to exit?")
.setIcon(R.drawable.usmtip)
.setCancelable(false)
.setNegativeButton(android.R.string.no, null)
.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface arg0, int arg1) {
HomeActivity.super.onBackPressed();
}
}).create().show();
}
}

0 Comments