Search code examples
androidonbackpressed

How to manipulate back button?


when I press on the back button, I want it will work like intent to go to some spesific activity and also refresh the page. I found some codes working in this way but couldn't find the one which is doing what I want exactly. Thanks in advance.


Solution

  • Try the below code..

    @Override
        public void onBackPressed() {             
            Log.d(TAG, "onBackPressed: GoTo NextActivity");
            Intent intent = new Intent(getApplicationContext(),NextActivity.class); // Replace the NextActivity.class with the Activity you wish to open..
            startActivity(intent);
        }