I created a sample application in Android Studio to learn about the life cycle of an Android application. I know that orientation change completely restarts the activity (i.e. OnCreate method is called again). As far as I know, orientation change should have destroyed the context and shown a blank text after device rotation. But somehow without overriding onSaveInstanceState and onRestoreInstanceState methods it is saving the context.
I don't have any fragments. It just the basic template that is provided by Android studio, with few overridden life cycle methods. Here is my MainActivity class:
package com.example.android.a2_screen_orientation_change;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
public class MainActivity extends AppCompatActivity {
private static final String TAG = MainActivity.class.getSimpleName();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@Override
protected void onStart() {
super.onStart();
Log.i(TAG, "in method onStart");
}
@Override
protected void onResume() {
super.onResume();
Log.i(TAG, "in method onResume");
}
@Override
protected void onRestart() {
super.onRestart();
Log.i(TAG, "in method onRestart");
}
@Override
protected void onPause() {
super.onPause();
Log.i(TAG, "in method onPause");
}
@Override
protected void onStop() {
super.onStop();
Log.i(TAG, "in method onStop");
}
@Override
protected void onDestroy() {
super.onDestroy();
Log.i(TAG, "in method onDestroy");
}
}
Layout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.android.a2_screen_orientation_change.MainActivity">
<EditText
android:id="@+id/editText"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
AbdroidManifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.android.a2_screen_orientation_change">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
