title: AndroidX : Parcelable encountered IOException writing serializable object only in Android version 10 devices
body: <p>I got <code>Parcelable encountered IOException writing serializable object</code> and it caused by <code>java.io.NotSerializableException: androidx.appcompat.widget.Toolbar</code> error only in Android Version 10 devices.</p>
  <p>I've searched many results for getting solutions to this problem but every solution I got, was telling to define <code>implement serializable</code> in both <em>inner class</em> and <em>sub inner class</em>  and I've done it, still, I got this error only in Android version 10 devices.</p>
  <p>If I will use <code>transient</code> this keyword to define View or object then this error will fix but this same error comes with another view, adapter, and class.</p>
  <p><strong>Logcat</strong></p>
  <pre><code>java.lang.RuntimeException: Parcelable encountered IOException writing serializable object (name = com.android.ui.fragment.CustomViewFragment)
          at android.os.Parcel.writeSerializable(Parcel.java:1850)
          at android.os.Parcel.writeValue(Parcel.java:1797)
          at android.os.Parcel.writeArrayMapInternal(Parcel.java:945)
          at android.os.BaseBundle.writeToParcelInner(BaseBundle.java:1584)
          at android.os.Bundle.writeToParcel(Bundle.java:1253)
          at android.os.Parcel.writeBundle(Parcel.java:1014)
          at android.content.Intent.writeToParcel(Intent.java:11155)
          at android.app.IActivityTaskManager$Stub$Proxy.startAppLockService(IActivityTaskManager.java:8468)
          at android.app.Activity.startAppLockService(Activity.java:8950)
          at android.app.Activity.performStart(Activity.java:8022)
          at android.app.ActivityThread.handleStartActivity(ActivityThread.java:3512)
          at android.app.servertransaction.TransactionExecutor.performLifecycleSequence(TransactionExecutor.java:221)
          at android.app.servertransaction.TransactionExecutor.cycleToPath(TransactionExecutor.java:201)
          at android.app.servertransaction.TransactionExecutor.executeLifecycleState(TransactionExecutor.java:173)
          at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:97)
          at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2175)
          at android.os.Handler.dispatchMessage(Handler.java:107)
          at android.os.Looper.loop(Looper.java:237)
          at android.app.ActivityThread.main(ActivityThread.java:7860)
          at java.lang.reflect.Method.invoke(Native Method)
          at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
          at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1075)
       Caused by: java.io.NotSerializableException: androidx.appcompat.widget.Toolbar
          at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1240)
          at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1604)
          at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1565)
          at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1488)
          at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1234)
          at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1604)
          at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1565)
          at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1488)
          at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1234)
          at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:354)
          at android.os.Parcel.writeSerializable(Parcel.java:1845)
          at android.os.Parcel.writeValue(Parcel.java:1797) 
          at android.os.Parcel.writeArrayMapInternal(Parcel.java:945) 
          at android.os.BaseBundle.writeToParcelInner(BaseBundle.java:1584) 
          at android.os.Bundle.writeToParcel(Bundle.java:1253) 
          at android.os.Parcel.writeBundle(Parcel.java:1014) 
          at android.content.Intent.writeToParcel(Intent.java:11155) 
          at android.app.IActivityTaskManager$Stub$Proxy.startAppLockService(IActivityTaskManager.java:8468) 
          at android.app.Activity.startAppLockService(Activity.java:8950) 
          at android.app.Activity.performStart(Activity.java:8022) 
          at android.app.ActivityThread.handleStartActivity(ActivityThread.java:3512) 
          at android.app.servertransaction.TransactionExecutor.performLifecycleSequence(TransactionExecutor.java:221) 
          at android.app.servertransaction.TransactionExecutor.cycleToPath(TransactionExecutor.java:201) 
          at android.app.servertransaction.TransactionExecutor.executeLifecycleState(TransactionExecutor.java:173) 
          at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:97) 
          at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2175) 
          at android.os.Handler.dispatchMessage(Handler.java:107) 
          at android.os.Looper.loop(Looper.java:237) 
          at android.app.ActivityThread.main(ActivityThread.java:7860) 
          at java.lang.reflect.Method.invoke(Native Method) 
          at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493) 
          at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1075) 
  </code></pre>
  <p><strong>Activity.java</strong></p>
  <pre><code>   public class BaseFragmentActivity extends AppCompatActivity implements Serializable, View.OnClickListener {
      
          private static final String TAG = &quot;BaseFragmentActivity&quot;;
          private Toolbar mToolbar;
          private ImageView tBtnSave, tBtnBack;
          private TextView tTxtTitle;
      
          @Override
          protected void onCreate(Bundle savedInstanceState) {
              super.onCreate(savedInstanceState);
              setContentView(R.layout.activity_base_fragment);
      
              mToolbar = findViewById(R.id.toolbar);
              tBtnSave = findViewById(R.id.toolbar_btn_save);
              tBtnBack = findViewById(R.id.toolbarBtnBack);
              tTxtTitle = findViewById(R.id.toolbar_title);
          }
  
          ...
  }
  </code></pre>
  <p><strong>build.gradle</strong></p>
  <pre><code>apply plugin: 'com.android.application'
  
  android {
      compileSdkVersion 29
      defaultConfig {
          applicationId &quot;com.android.app&quot;
          minSdkVersion 21
          targetSdkVersion 29
          versionCode 1
          versionName &quot;1.0&quot;
          testInstrumentationRunner &quot;androidx.test.runner.AndroidJUnitRunner&quot;
          vectorDrawables.useSupportLibrary = true
          multiDexEnabled true
      }
      buildTypes {
          debug {
              debuggable true
              buildConfigField &quot;Boolean&quot;, &quot;DEBUG_MODE&quot;, &quot;true&quot;
              proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
          }
          release {
              minifyEnabled false
              proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
          }
      }
  }
  
  dependencies {
      implementation fileTree(dir: 'libs', include: ['*.jar'])
      implementation 'com.android.support:support-annotations:28.0.0'
      annotationProcessor 'com.android.support:support-annotations:28.0.0'
      implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
      implementation 'androidx.legacy:legacy-support-v4:1.0.0'
      implementation 'androidx.appcompat:appcompat:1.1.0'
      implementation 'com.google.android.material:material:1.1.0'
  
      implementation 'com.google.code.gson:gson:2.8.5'
      implementation 'com.github.bumptech.glide:glide:4.11.0'
      annotationProcessor 'com.github.bumptech.glide:compiler:4.11.0'
      implementation 'com.android.volley:volley:1.1.1'
      implementation 'androidx.palette:palette:1.0.0'
  
      //External Animation Library
      implementation 'com.airbnb.android:lottie:3.4.1'
  
      testImplementation 'junit:junit:4.12'
      androidTestImplementation 'androidx.test.ext:junit:1.1.1'
      androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
  }
  </code></pre>
  <p><strong>Edit and Fixed.</strong></p>
  <pre><code>public class BaseFragmentActivity extends AppCompatActivity implements Serializable, View.OnClickListener {
      
          // By using `transient` keyword to define view or class to say it's not serialized view or class.
  
          private static final String TAG = &quot;BaseFragmentActivity&quot;;
          private transient Toolbar mToolbar;
          private transient AppCompatImageView tBtnSave, tBtnBack;
          private transient AppCompatTextView tTxtTitle;
      
          @Override
          protected void onCreate(Bundle savedInstanceState) {
              super.onCreate(savedInstanceState);
              setContentView(R.layout.activity_base_fragment);
      
              mToolbar = findViewById(R.id.toolbar);
              tBtnSave = findViewById(R.id.toolbar_btn_save);
              tBtnBack = findViewById(R.id.toolbarBtnBack);
              tTxtTitle = findViewById(R.id.toolbar_title);
          }
  
          ...
  }
  </code></pre>