0

I added in android manifest a back button in my navigation bar on top of screen to go back to the previous activity using this:

<meta-data
                android:name="android.support.PARENT_ACTIVITY"
                android:value=".main.MainActivity"/>

and now when ever i use the back button in my nav bar, the content of MainActivity gets refreshed it's like clearing task, however when i use my normal back button (on Bottom of screen) my MainActivity's content does not get refreshed as i am only starting the intent programmatically and i haven't cleared task using intent flags.

how can i prevent the back button in nav bar in the title from clearing the previous activity's task using androidManifest?

thanks in advance

nick isra
  • 99
  • 1
  • 9

1 Answers1

0

Just call onBackPressed() method from your back button, like this

backButton.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        onBackPressed();
    }
});

onBackPressed() will work as your hardware's back button

To add custom back button try this https://stackoverflow.com/a/16103355/5705721

Makarand
  • 983
  • 9
  • 27
  • ah sorry, i didnt include that i was using kotlin, and i don't believe i can call the backButton as i can't give it any id? – nick isra Oct 12 '19 at 07:58
  • show the code where you are calling MainActivity. You don't need to give any id for using onBackPressed() – Makarand Oct 12 '19 at 09:21
  • i don't have any core i just added the 2 lines in my androidManifest , and a back button appeared before the title. when i press it it goes back to my main activity.and i can't give it an id to add setOnclickListener – nick isra Oct 12 '19 at 12:53