Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8266275
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T05:06:02+00:00 2026-06-08T05:06:02+00:00

I am saving a few songs in a playlist (in my application database). When

  • 0

I am saving a few songs in a playlist (in my application database). When a particular song is deleted from the SDCard which already exists in the playlist, how can I reflect the changes in my database?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T05:06:06+00:00Added an answer on June 8, 2026 at 5:06 am

    Look into using a FileObserver

    You can monitor either a single file or directory. So what you’ll have to do is determine which directories you have songs in and monitor each. Otherwise you can monitor your external storage directory and then each time anything changes, check if its one of the files in your db.

    It works real simple, something like this should work:

    import android.os.FileObserver;
    public class SongDeletedFileObserver extends FileObserver {
        public String absolutePath;
        public MyFileObserver(String path) {
            //not sure if you need ALL_EVENTS but it was the only one in the doc listed as a MASK
            super(path, FileObserver.ALL_EVENTS);
            absolutePath = path;
        }
        @Override
        public void onEvent(int event, String path) {
            if (path == null) {
                return;
            }
            //a new file or subdirectory was created under the monitored directory
            if ((FileObserver.DELETE & event)!=0) {
                //handle deleted file
            }
    
            //data was written to a file
            if ((FileObserver.MODIFY & event)!=0) {
                //handle modified file (maybe id3 info changed?)
            }
    
            //the monitored file or directory was deleted, monitoring effectively stops
            if ((FileObserver.DELETE_SELF & event)!=0) {
               //handle when the whole directory being monitored is deleted
            }
    
            //a file or directory was opened
            if ((FileObserver.MOVED_TO & event)!=0) {
               //handle moved file
            }
    
            //a file or subdirectory was moved from the monitored directory
            if ((FileObserver.MOVED_FROM & event)!=0) {
                //?
            }
    
            //the monitored file or directory was moved; monitoring continues
            if ((FileObserver.MOVE_SELF & event)!=0) {
                //?
            }
    
        }
    }
    

    Then of course you need to have this FileObserver running at all times for it to be effective so you need to put it in a service. From the service you would do

    SongDeletedFileObserver fileOb = new SongDeletedFileObserver(Environment.getExternalStorageDirectory());
    

    There are some tricky things to this that you have to keep in mind:

    1. This will drain battery worse if you have it running all the time..
    2. You’ll have to synchronize when the sdcard is mounted (and on reboot). This could be slow
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having a few issues with duplicate records in my database which I believe
I have a few things about saving logged in user, save_model() and save_formset() from
I am writing an application and I finally have it saving to the database
Basically , i am saving few feed urls in Django model and for parsing,
I want to download few HTML pages from http://abc.com/view_page.aspx?ID= The ID is from an
I'm haing a few problems updating a row in my database using Linq2Sql. Inside
I am creating a few JAX-WS endpoints, for which I want to save the
I have a few different contact forms in my CakePHP 2.0 application. All of
Say I have a few tables in the MSSQL database, each with about 5-10
I need to do some trimming before saving various fields in our database. We're

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.