mirror of
https://gitee.com/zhangsken/AndroidIDE.git
synced 2026-10-16 07:49:44 +08:00
fix: preferences fragment is recreated after configuration change
This commit is contained in:
@@ -20,6 +20,7 @@ package com.itsaky.androidide.activities;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.fragment.app.Fragment;
|
||||
|
||||
import com.itsaky.androidide.R;
|
||||
@@ -46,7 +47,11 @@ public class PreferencesActivity extends IDEActivity {
|
||||
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
||||
|
||||
binding.toolbar.setNavigationOnClickListener(v -> onBackPressed());
|
||||
|
||||
|
||||
if (savedInstanceState != null) {
|
||||
return;
|
||||
}
|
||||
|
||||
final var prefs = IDEPreferences.INSTANCE;
|
||||
prefs.getChildren().clear();
|
||||
prefs.addPreference(new ConfigurationPreferences());
|
||||
@@ -55,10 +60,12 @@ public class PreferencesActivity extends IDEActivity {
|
||||
final var args = new Bundle();
|
||||
args.putParcelableArrayList(
|
||||
IDEPreferencesFragment.EXTRA_CHILDREN, new ArrayList<>(prefs.getChildren()));
|
||||
getRootFragment().setArguments(args);
|
||||
loadFragment(getRootFragment());
|
||||
|
||||
final var root = getRootFragment();
|
||||
root.setArguments(args);
|
||||
loadFragment(root);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected View bindLayout() {
|
||||
binding = ActivityPreferencesBinding.inflate(getLayoutInflater());
|
||||
|
||||
@@ -21,16 +21,11 @@
|
||||
|
||||
</com.google.android.material.appbar.AppBarLayout>
|
||||
|
||||
<LinearLayout
|
||||
|
||||
<FrameLayout
|
||||
android:id="@+id/fragmentContainer"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
app:layout_behavior="com.google.android.material.appbar.AppBarLayout$ScrollingViewBehavior">
|
||||
|
||||
<FrameLayout
|
||||
android:id="@+id/fragmentContainer"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent" />
|
||||
|
||||
</LinearLayout>
|
||||
app:layout_behavior="com.google.android.material.appbar.AppBarLayout$ScrollingViewBehavior" />
|
||||
|
||||
</androidx.coordinatorlayout.widget.CoordinatorLayout>
|
||||
|
||||
@@ -40,9 +40,9 @@ abstract class BaseIDEActivity : AppCompatActivity() {
|
||||
open val statusBarColor: Int
|
||||
get() = resolveAttr(R.attr.colorSurface)
|
||||
|
||||
fun loadFragment(fragment: Fragment?, id: Int) {
|
||||
fun loadFragment(fragment: Fragment, id: Int) {
|
||||
val transaction = supportFragmentManager.beginTransaction()
|
||||
transaction.replace(id, fragment!!)
|
||||
transaction.replace(id, fragment)
|
||||
transaction.commit()
|
||||
}
|
||||
|
||||
|
||||
Binary file not shown.
Reference in New Issue
Block a user