I created an activity as mainActivity and create navigation bar to navigate to other 4 distinct screen or fragment. In one of the fragment name settingFragment, i created a change language button which help to intent to another activity(languageActivity) but when i return back to main activity from languageActivity with back button it redirect me to homeFragment instead of settingFragment where i left. Is there a block code i am missing to happen that…
settingFragment
LinearLayout changelanguage = view.findViewById(R.id.layoutChangeLanguage);
changelanguage.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(getActivity(), LanguageActivity.class);
startActivity(intent);
}
});
languageActivity
ImageButton backButton = findViewById(R.id.Back_Button);
backButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view){
Intent intent = new Intent(getApplicationContext(), MainActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); // To clear all the stack activity
startActivity(intent);
onBackPressed();
}
});
Rinchen is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.