Reputation: 669
I have made an app which is working fine in emulator as well as small and medium size phones.But while running in tablet,it always shows landscape mode only.I have also used separate layout and layout-land layouts.I am not getting the reason behind it.This is the code:
public class SplashActivity extends FragmentActivity
{
public void onCreate(Bundle paramBundle)
{
super.onCreate(paramBundle);
requestWindowFeature(1);
getWindow().setFlags(1024, 1024);
FragmentManager fragmentmanager = getSupportFragmentManager();
FragmentTransaction fragmenttransaction = fragmentmanager.beginTransaction();
if (getResources().getConfiguration().orientation ==
Configuration.ORIENTATION_LANDSCAPE) {
setRequestedOrientation(0);
}
else
{
setRequestedOrientation(1);
}
fragmenttransaction.commit();
setContentView(R.layout.welcome);
new Handler().postDelayed(new SplashThread(), 2000L);
}
class SplashThread implements Runnable
{
SplashThread()
{
}
public void run()
{
SplashActivity.this.startActivity(new Intent(SplashActivity.this, McqHomePage.class));
SplashActivity.this.finish();
}
}
}
Please help me.Thanks in advance.
Upvotes: 1
Views: 453
Reputation: 14274
If you don't care about the orientation, you might as well leave out this bit of code entirely:
if (getResources().getConfiguration().orientation ==
Configuration.ORIENTATION_LANDSCAPE) {
setRequestedOrientation(0);
}
else
{
setRequestedOrientation(1);
}
The code above also has the ugly side-effect that certain orientation changes will always result in portrait -- for example, reverse-landscape would not be caught by your code. Additionally, instead of using 0 or 1, please use the constants provided, so that if the values change, your code won't break.
In the meantime, check your manifest -- I bet you added an orientation attribute there.
Upvotes: 1