Android - Keep VideoView playing after pressing HOME or BACK button - android

In Android development, is it possible to keep a VideoView playing after sending the user to HOME screen, so, when the user opens the Application once again, the video is already running?
Like, when I leave the activity, the video stops playing and when I go back to the same Activity, the video restarts. Is there some way to keep it running, like in the background?
Thank you!

In your onPause() of the activity you can pause the video get the current seekLevel by getCurrentPosition() and in your on resume if the video was playting you can pick up where you left of

Related

how to detect pause state of an activity started with startActivityForResult in Android

Is there any way to detect the pause state of the activity that has been started with startActivityForResult in Android.
I am launching the camera app in android to start recording a video however, after taking the video if the user doesn't click on either ok or cancel and simply clicks on the home button i would like to capture that event and delete the video taken and kill the camera. Is it possible in android?

how to turn back to same activity instance

I have made a Mediaplayer (just play songs from SD card) and it is not a service but a single activity. by pressing the home button the player continues playing in the back ground.
now my problem is how to get back to the same instance of the activity by launching the application. mine starts a new activity while the previous instance of mediaplayer is still playing the song.
I have seen many similar questions but mostly was about the services specially in mediaplayer cases.
is it possible to set some flags onDestroy and check them again onCreate or somthing similar ?
thanks
mine starts a new activity while the previous instance of mediaplayer is still playing the song
Yes, this is a behavior, on start - new Activity has been created.
I have seen many similar questions but mostly was about the services
There is no way, run Player in Service in order to bind new created Activity with the Player
Try using the launch mode - single instance, for your activity.
android:launchMode=[ "singleInstance"]
in your Media Player activity in Android Manifest.xml file. It might work.
If you press HOME to put the application in the background, and then launching the application creates a new Activity, you are probably seeing this long-standing nasty Android bug: https://stackoverflow.com/a/16447508/769265
To check if you are seeing this bug, just force close your application, then launch from the HOME screen, start playing sound, press HOME button, then launch application again from HOME screen. It shouldn't create a new instance of your activity.
Pleae don't set launchMode="singleInstance". This is not necessary and will create more problems than it will solve.

What method is called when i change activities?

I have a MediaPlayer that keeps playing when I change activities and when I even click the physical Home button on my phone. How can I make it so that the MediaPlayer keeps playing when I change activities yet stops playing when I click the Home screen button?
You can use a service. that keeps running the background.
the service is similar to normal activities but they run in background and dont have a user interface

Phonegap app closing problem

I am using phonegap with Android.I have a sound playing repeatedly with a timer.If I close the app the sound continues to play.Is there a app closing handler or something I could use to make the sound stop when the app exits.
I am using a Samsung Captivate(Galaxy S).If I press the back button the sound stops when the app exits.But if I press the home button then the sound just goes on forever when the app exits.
Thanks
You can catch the backbutton and stop the music playing and then close the app.
It's however not possible (as far as i know) to catch the close event.
http://wiki.phonegap.com/w/page/29494136/Android-Back-Button-Handler
Here is how to do that.

Android: Confused about application states

I have seen this post here (http://stackoverflow.com/questions/151777/how-do-i-save-an-android-applications-state). I am having a similar problem I believe.
I have an app which listens to an audio stream (using the mediaPlayer object). If I press the Home button it will continue streaming and hide my app. Then, at a later point I can go back to my app and press stop when I'm done. This is what I want. If however I press the Back button, when I later open my app again the app has been redrawn from fresh. Text boxes, buttons, everything has reset like I've just opened the app for the first time so I can't stop my audio stream. Clicking stop does nothing because the app has 'forgotten' it is streaming (the stream runs under a separate handler from the main UI thread, so I'm guessing since its been 'reset' it has lost track of its handlers?).
Why does this happen with the Back button, and how can I stop it?
Move the streaming functionality into an Android Service. Use an Activity to bind to the Service and to interact with it.

Categories

Resources