Parcelable from activity to fragment
<p>I am new to parcelable and I am trying to pass data from an Activity (MainActivity) to a fragment (MainFragment) but I`m struggle to get this right.</p>

<p>I made a class (InfoBean) with all the (parcelable) data. When I <strong>send the data from the MainActivity</strong>, the data from bean.newTheme (<strong>2131296447</strong>) is there but as soon as I try to <strong>retrieve in the Fragment</strong>, the value is <strong>0</strong>!</p>

<p>Could someone pls have a look, what I`m doing wrong? Thank you for your help.</p>

<p>Send data (MainActivity):</p>

<pre><code>public class MainActivity extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener {

    InfoBean bean = new InfoBean();

  @Override
  protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_main);

  SecureSharedPreferences theme = SecureSharedPreferences.getInstance(this, "MyPrefsFile");

        int newTheme = theme.getInt("themeCustom", 0);
        bean.newTheme = newTheme;

        Bundle bundle = new Bundle();
        bundle.putInt("theme", bean.newTheme); // debug shows value 2131296447 
        MainFragment mf = new MainFragment();
        mf.setArguments(bundle); 
    //
  }
}
</code></pre>

<p>Retrieve data (MainFragment):</p>

<pre><code>public class MainFragment extends Fragment {

  InfoBean bean = new InfoBean();

  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {

   //
   Bundle bundle = this.getArguments(); // Debugging shows 0!
     if (bundle != null) {
         bean.newTheme = bundle.getInt("theme");
        }

     if (bean.newTheme == 2131296447) { // White Theme
         mCardView1.setBackgroundColor(Color.parseColor("#E8EBED"));
        } else { // Dark Theme
         mCardView1.setBackgroundColor(Color.parseColor("#282929"));
         relLay.setBackgroundColor(Color.parseColor("#1B1C1C"));
        }

        return rootView;
    }
}
</code></pre>

<p>InfoBean.class:</p>

<pre><code>public class InfoBean implements Parcelable {

    public int newTheme;
    public int THEME_DARK = R.style.DarkTheme;
    public int THEME_LIGHT = R.style.LightTheme;

@Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeInt(this.newTheme);
        dest.writeInt(this.THEME_DARK);
        dest.writeInt(this.THEME_LIGHT);

}

    public InfoBean() {
    }

    protected InfoBean(Parcel in) {
        this.newTheme = in.readInt();
        this.THEME_DARK = in.readInt();
        this.THEME_LIGHT = in.readInt();

}

    public static final Parcelable.Creator&lt;InfoBean&gt; CREATOR = new Parcelable.Creator&lt;InfoBean&gt;() {
        @Override
        public InfoBean createFromParcel(Parcel source) {
            return new InfoBean(source);
        }

        @Override
        public InfoBean[] newArray(int size) {
            return new InfoBean[size];
        }
    };
}
</code></pre>