バックスタックに積まずにナビゲーションするメソッドを追加

This commit is contained in:
r-ca 2024-01-22 23:47:46 +09:00
parent 3178e9233b
commit d5df291c81
No known key found for this signature in database
GPG Key ID: 6A72911AC73464A9

View File

@ -96,4 +96,18 @@ public class MainActivity extends AppCompatActivity implements FragmentNavigatio
.addToBackStack(null)
.commit();
}
@Override
public void navigateToFragment(Fragment fragment, boolean addToBackStack) {
if (addToBackStack) {
getSupportFragmentManager().beginTransaction()
.replace(R.id.nav_host_fragment, fragment)
.addToBackStack(null)
.commit();
} else {
getSupportFragmentManager().beginTransaction()
.replace(R.id.nav_host_fragment, fragment)
.commit();
}
}
}