1

I have 2 activities SingActivity and ExoPlayerActivity. In SingActivity, user records a song and the song is saved in internal storage. As soon as the song is saved, I am opening ExoPlayerActivity to play the song. The ExoPlayerActivity has a save button.

If user presses save button, then I am doing nothing as song is already saved after recording. If user does not press save button and exists from ExoPlayerActivity, I am deleting the file which was saved. Suppose user is in ExoPlayerActivity and user puts the app in background and swipes the app from background, then too I want to delete the file as saved is not pressed.

So my question is where to put the delete code? I can't put in onDestroy or in finish() as they are not called every time and may cause problem in case of resource constraint scenario.

halfer
  • 19,824
  • 17
  • 99
  • 186
BraveEvidence
  • 53
  • 11
  • 45
  • 119
  • It sounds like you should be using the cache for the initial recording. Store the file in the application's cache then move it out of the cache when the user saves the file. That way you don't really need to care about the file. – Chris Stillwell Apr 24 '18 at 14:54
  • Check this [link](https://stackoverflow.com/questions/26842675/continue-service-even-if-application-is-cleared-from-recent-app). – Surender Kumar Apr 24 '18 at 15:03

2 Answers2

1

With this approach it will be really buggy (in case if it was even possible) i suggest that you use android cache to do this:

refer to Android developers| Save files on device storage

or you can see this answer on stackoverflow: Creating temporary files in Android

Yamen Nassif
  • 2,416
  • 2
  • 24
  • 48
0

Maybe try to get a look at onTrimMemory. If it's not useful, try to take a look at this answer, it requires that you implement a different approach, but it may be what you're looking for.

jack_the_beast
  • 1,838
  • 4
  • 34
  • 67