I am using the following code to implement the back button in the toolbar:
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_series);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar( toolbar );
Objects.requireNonNull(getSupportActionBar()).setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowHomeEnabled(true);
toolbar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startActivity(new Intent(SeriesActivity.this, BowlerActivity.class));
finish();
}
});
My problem is when the .setNavigationOnClickListener registers the click it goes back to the previous activity minus the proper Bowlers. When I go to the Series Activity I am passing the leagueId and the bowlerId to it. When I go back to the BowlerActivity I am not passing anything back so I get the following:
Bowlers B1 and B2 belong to a different League.
I have gone through several different threads like this one how to override action bar back button in android? and I have tried several of the different suggestions in them. None of them worked for me.
How do I pass the leagueId and the bowlerId back to the BowlerActivity so that when it starts up I am filtering the proper Bowler from the database to display in the listview.
Do I even need to pass these values back? Any assistance would be appreciated.
From your SeriesActivity call the BowlerActivity using startActivityForResult() method
For example:
In your BowlerActivity set the data which you want to return back to SeriesActivity. If you don't want to return back, don't set any.
Now in your SeriesActivity class write following code for the onActivityResult() method.
Source => https://stackoverflow.com/a/10407371/9956766