简体   繁体   中英

How to pause and resume application?

I have made a simple application which plays video in Video-view. Now i want my application to run when my phone is idle as in when no activity is running and to pause when some other activity runs.

So what I have understood from your question is you want to pause video playback when some other app comes to foreground.

The simplest answer is onPause() method of an activity.

When another activity comes to foreground, your activity goes in pause state, that's where you can write the code for stopping video playback, save the current instance (time) at which the video is running and when your activity again comes to foreground, restore that data and start playing the video from the same position it was paused.

For restoring the data when the activity restores, you can write the code in onResume() .

Hope this helps

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM