Question

I know to pass an intent to goto the home screen using this code:

Intent startMain = new Intent(Intent.ACTION_MAIN);
            startMain.addCategory(Intent.CATEGORY_HOME);
            startMain.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            startActivity(startMain);

But I want to press the back button using an intent in android.

Was it helpful?

Solution

You need to override back pressed somewhere in your activity @Override public void onBackPressed() { //Do whatever custom stuff you wish here super.onBackPressed(); }

Then you may call backPressed in whatever way you may wish and wherever you may wish:

MyActivity.this.onBackPressed();
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top