Physther
Physther

Reputation: 246

When pressing the back button on the phone, the app minimizes

I made a button (id: btnCheck) that should send me to an activity depending on the language selected. Everything works fine, except the fact that when I'm in the triggered Activity (MainMenu.class) and I press the Back button on the phone, the app minimizes and then goes back to the origin (MainStartActivity.class). The code is large and badly organized, but I have realized that the problem comes from the code below.

Can anyone help me to realize what is wrong in the code below that the app minimizes when the back button is pressed?

btnCheck.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View view) {
    LanguageType languageType=new LanguageType();
    if(selectedLanguage.equalsIgnoreCase(AppConstants.English)){
    languageType.languageType=AppConstants.English;
    PrefUtils.setLanguage(languageType,MainScreenActivity.this);
    Log.e("Selected Language",PrefUtils.getLanguage(MainScreenActivity.this).languageType);
    Configuration config = new Configuration();
    config.locale = Locale.ENGLISH;
    getResources().updateConfiguration(config, 
    getResources().getDisplayMetrics());
}       
    Intent i=new Intent(MainScreenActivity.this,MainMenu.class);
    startActivity(i);
    finish();

Upvotes: 0

Views: 59

Answers (1)

Gabe Sechan
Gabe Sechan

Reputation: 93624

Remove the call to finish. Finish ends the current activity and removes it from the stack. With that gone, you should return to this activity when you hit back on the next one.

Upvotes: 2

Related Questions