【发布时间】:2014-02-27 22:16:58
【问题描述】:
我的应用中实际上有 3 个活动。
我刚刚创建了一个活动,并使用处理程序将其作为 SPLASH SCREEN。
即,我的初始屏幕显示 3 秒,然后应用程序的主要生命周期继续。到此为止,一切都很完美。
我的问题是在加载启动画面时,如果我改变方向,整个应用程序都会崩溃。
我的要求是以横向和纵向模式加载应用程序。
我尝试过 onConfig 更改等,但徒劳无功....
我的悲伤故事都包含在这里......
public class Asplash extends Activity{
Handler handler = new Handler();
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.splash);
try {
handler.postDelayed(new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
finish();
Intent i = new Intent(Asplash.this, Example.class);
i.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
startActivity(i);
}
}, 3000);
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
}
@Override
protected void onPause() {
// TODO Auto-generated method stub
handler.removeCallbacksAndMessages(null);
finish();
super.onPause();
}
}
这是清单文件:
<activity android:name=".Asplash"
android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen"
android:configChanges="orientation">
<intent-filter >
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activity
android:name="com.example.Example"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
我只想制作这个“Asplash”活动,以横向和纵向显示。我还尝试在 LAYOUT 和 LAYOUT-LAND 文件夹中为“splash”创建 XML 文件。然后也是同样的恐慌......
实际上在 ANDROID 中,它应该像基本示例一样自动调整 ORIENTATION 变化。但我不明白为什么它在这里不起作用......
【问题讨论】:
-
解决方案在这里:android:configChanges
-
finish() 应该是最后一个
标签: android splash-screen screen-orientation