I'm experiencing a small undesired effect when trying to set the orientation of my activity:
I hace two activities: MainActivity and Activity2.
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
findViewById(R.id.button).setOnClickListener(v -> startActivity(new Intent(this, Activity2.class)));
}
}
public class Activity2 extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main2);
}
}
When I click the button with the device in portrait (but displaying the MainActivity in landscape) it loads the Activity2 in portrait and takes like 1 second to rotate to landscape.
How can I avoid this and load the Activity2 with the correct orientation from the start?
Note: This is a simplified example. It is not possible to set up the orientation in the manifest since the orientation is not fixed and depends on the user input.
from Avoid setRequestedOrientation delay
No comments:
Post a Comment