在我的应用程序中,我有MainActivty应该总是在protrait中查看。如果我将设备转向横向,则切换到TrendsActivity(以显示一些图)。当我切换回波泰特我只是在TrendsActivity称之为改变方向变化时的活动
@Override
public void onConfigurationChanged(Configuration newConfig)
{
super.onConfigurationChanged(newConfig);
// Checks the orientation of the screen
if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE)
{
Intent intent = new Intent(this, TrendsActivity.class);
startActivity(intent);
}
}
然后:
@Override
public void onConfigurationChanged(Configuration newConfig)
{
super.onConfigurationChanged(newConfig);
// Checks the orientation of the screen
if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT)
{
finish();
}
}
这完成的全自动移回MainActivity活动这是由folliwing代码MainActivty完成。到现在为止还挺好。但是如果我在TrendsActivity中按下后退按钮,我会以横向模式返回到MainActivity,而我不想那样做。我试图调用MainActivity下面的代码:
@Override
protected void onRestart()
{
super.onRestart();
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT);
}
这是不行的,因为现在的onConfigurationChanged()如果MainActivity不会被调用......
怎么办?
为什么不直接在清单中指定说MainActivity应打开肖像模式和TrendsActivity应在开阔的景观中的代码?试过了吗? – JoelFernandes