I achieved something similar by using ViewFlipper.
SettingsActivity
public class SettingsActivity extends AppCompatActivity {
boolean state;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_settings);
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
SharedPreferences.Editor editor = sharedPreferences.edit();
Button right = findViewById(R.id.right);
Button left = findViewById(R.id.left);
right.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
state = true;
editor.putBoolean("handstate", state);
editor.apply();
}
});
left.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
state = false;
editor.putBoolean("handstate", state);
editor.apply();
}
});
}
ViewFlippingActivity
public class VIewFlippingActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_view_flipping);
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
ViewFlipper flipper = findViewById(R.id.flipper);
RelativeLayout layoutRight = findViewById(R.id.layoutRight);
RelativeLayout layoutLeft = findViewById(R.id.layoutLeft);
boolean statereceive = sharedPreferences.getBoolean("handstate", false);
if (statereceive == true) {
flipper.setDisplayedChild(flipper.indexOfChild(findViewById(R.id.layoutRight)));
} else if (statereceive == false){
flipper.setDisplayedChild(flipper.indexOfChild(findViewById(R.id.layoutLeft)));
} else {
flipper.setDisplayedChild(flipper.indexOfChild(findViewById(R.id.layoutRight)));
}
}
viewflipping_activity.xml
<ViewFlipper xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:id="@+id/flipper"
android:layout_height="match_parent"
tools:context=".VIewFlippingActivity">
<RelativeLayout
android:id="@+id/layoutRight"
android:layout_width="match_parent"
android:layout_height="600dp"
android:background="@color/royal_android">
//your content
</RelativeLayout>
<RelativeLayout
android:id="@+id/layoutLeft"
android:layout_width="match_parent"
android:layout_height="600dp"
android:background="@color/royal_blue">
//your content
</RelativeLayout>
</ViewFlipper>
Sorry for the bad Explanation and difficult to read code im in a hurry.
Hope it still provides some sort of help.