Skip to content

Commit 2c23bff

Browse files
committed
fix orientation change crash
1 parent 3bb94cd commit 2c23bff

2 files changed

Lines changed: 5 additions & 6 deletions

File tree

app/src/main/AndroidManifest.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
android:theme="@style/AppTheme">
1010
<activity
1111
android:name=".MainActivity"
12+
android:configChanges="orientation|screenSize"
1213
android:label="@string/app_name">
1314
<intent-filter>
1415
<action android:name="android.intent.action.MAIN"/>

app/src/main/java/yalantis/com/sidemenu/sample/MainActivity.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,10 @@ public class MainActivity extends ActionBarActivity implements ViewAnimator.View
4040
protected void onCreate(Bundle savedInstanceState) {
4141
super.onCreate(savedInstanceState);
4242
setContentView(R.layout.activity_main);
43-
if (savedInstanceState == null) {
44-
contentFragment = ContentFragment.newInstance(R.drawable.content_music);
45-
getSupportFragmentManager().beginTransaction()
46-
.add(R.id.content_frame, contentFragment)
47-
.commit();
48-
}
43+
contentFragment = ContentFragment.newInstance(R.drawable.content_music);
44+
getSupportFragmentManager().beginTransaction()
45+
.replace(R.id.content_frame, contentFragment)
46+
.commit();
4947
drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
5048
drawerLayout.setScrimColor(Color.TRANSPARENT);
5149
linearLayout = (LinearLayout) findViewById(R.id.left_drawer);

0 commit comments

Comments
 (0)