How to disable onBackPressed button in android

Have you ever wondered how to disable onBackPressed button in android? If you are search for a solution on how to disable onBackPressed button in android, it is as simple as overriding the onBackPressed method of the activity class and commenting out onBackPressed()

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

import com.bluapp.androidview.R;

public class DisableOnBackPressActivity extends AppCompatActivity {

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

    @Override
    public void onBackPressed(){
        //super.onBackPressed();
    }
}

By commenting out theĀ super.onBackPressed()method, the android back button is automatically disabled.

If you have any questions or suggestions kindly use the comment box or you can contact us directly through our contact page below.

 

Add a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.