屏幕方向更改后继续活动 - Android
我目前有一个可以播放音频文件的类,但是如果我将屏幕倾斜到水平或纵向,它就会重新启动。倾斜屏幕后,如何使我的应用程序从中断处继续?请注意,我不希望我的应用程序固定在纵向/水平位置。
Public void Play(){
AudioRenderer mr = new AudioRenderer();
mp = mr.AudioRenderer(filePath);
}
private class AudioRenderer extends Activity {
private MediaPlayer AudioRenderer(String filePath) {
File location = new File(filePath);
Uri path = Uri.fromFile(location);
mp= MediaPlayer.create(this, path);
}
return mp}
多谢!!
i currently have a class that'll play audio Files, however if i tilt my screen to horizontal or portrait, it just restarts. How can i make my app continue from where it left off after i tilt my screen? Note that i do not want my app to be fixed in the portrait/horizontal position.
Public void Play(){
AudioRenderer mr = new AudioRenderer();
mp = mr.AudioRenderer(filePath);
}
private class AudioRenderer extends Activity {
private MediaPlayer AudioRenderer(String filePath) {
File location = new File(filePath);
Uri path = Uri.fromFile(location);
mp= MediaPlayer.create(this, path);
}
return mp}
Thanks a lot!!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以通过在 AndroidManifest.xml 文件中设置 Activity 的属性来实现此目的。这告诉您的 Activity 不要终止该 Activity,并在方向或键盘更改时再次调用 onCreate
You can accomplish this by setting an attribute on your activity in your AndroidManifest.xml file. This tells your activity to not kill the activity and call onCreate again on orientation or keyboard changes
您应该在 android menifest 文件中的每个活动元素中添加以下行
you should add the following line in each of your activity Element in android menifest file