2

In my app I don't want to restart a media player once it starts if the user rotates the phone. How can I prevent a re-start of my app when it is rotated because it stops the running sound file that is playing?

Please show me the code I need to add and where to add it.

Thanks.

Truly, Emad

casperOne
  • 72,334
  • 18
  • 180
  • 242
Emad-ud-deen
  • 4,532
  • 19
  • 80
  • 148

2 Answers2

5

use this

  <activity android:screenOrientation="landscape" android:configChanges="orientation|keyboardHidden" android:name="VncCanvasActivity">

see this

Community
  • 1
  • 1
confucius
  • 12,867
  • 10
  • 46
  • 66
1

You have to redesign your application to play the music from a service instead of from your main activity. Your main activity can at any time be killed by the operating system if it decides it needs memory.

See What is a service

richardwiden
  • 1,548
  • 2
  • 12
  • 22
  • I'd just like to point out that a Service is not immune to being killed than an Activity is. I think your suggestion to use a Service is still valid, however. Since it will be a user-visible Service, see http://stackoverflow.com/questions/3856767/android-keeping-a-background-service-alive-preventing-process-death – Jon Willis Sep 11 '11 at 17:39
  • It is however less likely which is what you most likely want. But agreed a bit clumsily formulated. – richardwiden Sep 11 '11 at 17:43
  • Hi Richard, I'm going to see what makes this code at http://www.java2s.com/Code/Android/Media/UsingServicetoplaymediafile.htm works since it uses a service to play a media file. If I can fiture it out I will apply it into my app. Thanks everyone for the fast replies. – Emad-ud-deen Sep 11 '11 at 18:45
  • Hi Richard, I tried the code but it had parts missing but did find a better one at http://marakana.com/forums/android/examples/60.html and it had everything I needed to get a working demo of the media file to play even when I moved the phone around from portrait to landscape. I will now get that into my app. Truly, Emad – Emad-ud-deen Sep 11 '11 at 19:59