屏幕方向更改后继续活动 - Android

发布于 2024-12-01 06:50:14 字数 487 浏览 9 评论 0原文

我目前有一个可以播放音频文件的类,但是如果我将屏幕倾斜到水平或纵向,它就会重新启动。倾斜屏幕后,如何使我的应用程序从中断处继续?请注意,我不希望我的应用程序固定在纵向/水平位置。

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

神也荒唐 2024-12-08 06:50:14

您可以通过在 AndroidManifest.xml 文件中设置 Activity 的属性来实现此目的。这告诉您的 Activity 不要终止该 Activity,并在方向或键盘更改时再次调用 onCreate

<activity android:name="YourActivity" android:configChanges="orientation|keyboardHidden"/>

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

<activity android:name="YourActivity" android:configChanges="orientation|keyboardHidden"/>
一袭水袖舞倾城 2024-12-08 06:50:14

您应该在 android menifest 文件中的每个活动元素中添加以下行

 android:configChanges="orientation|keyboard|keyboardHidden" 

you should add the following line in each of your activity Element in android menifest file

 android:configChanges="orientation|keyboard|keyboardHidden" 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文