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 8765439
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T16:16:58+00:00 2026-06-13T16:16:58+00:00

I have a problem with MediaScanner. I use it to scan a single File

  • 0

I have a problem with MediaScanner. I use it to scan a single File with this code:

public class SingleMediaScanner implements MediaScannerConnectionClient {

private static final String TAG = "SingleMediaScanner";

public MediaScannerConnection mMs;
private String mFile;

public SingleMediaScanner(Context context, String s) {
    mFile = s;
    mMs = new MediaScannerConnection(context, this);
    mMs.connect();
}

public void onMediaScannerConnected() {
    Log.d(TAG, "MediaScanner conectado");
    mMs.scanFile(mFile, null);
}

public void onScanCompleted(String path, Uri uri) {
    Log.d(TAG, "MediaScanner terminó de escanear");
    mMs.disconnect();
}
}

If I scan a file at the beginning of an activity (onCreate), it works perfect. The scanner is connected, it scans the file and after that, is completed.

But if I call the scanner and then I go to another activity, the MediaScanner leaks memory because it doesn’t call the onScanCompleted method. And if I use unbindService() with the scanner before leaving the activity, the scanner doesn’t work (the file doesn’t appear in the gallery app).

I need to use the scanner when I leave the activity. What can I do?

  • 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-13T16:16:59+00:00Added an answer on June 13, 2026 at 4:16 pm

    There are other ways to add the file to the Gallery by using the static scanFile() method or by sending a BroadCast. Normally these should suit your need fine. You only need a MediaScannerConnection if you need some control over the addition process.

    I have written a blog post about how to use the other methods to trigger the MediaScanner.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have problem to make work a resource file. This is my simple code
I have problem with css styles in aspx.cs file HttpContext.Current.Response.Write(<table class=\'bordered\' cellpadding=\'5\' color: \'red\'
Have problem with this code var MAIN_LOCATION = http://www.bosscaffe.com/new/; $(#gallery_page).click(function() { $('#gallery_photos').show(); getPhotos(); return
I have problem with importing jar file and running in Geany IDE . This
I have problem compilin this code..can anyone tell whats wrong with the syntax CREATE
I have problem with my query on C, I’m using the oci8 driver. This
I have problem with TableView its empty. In (.h) file: @interface TableViewController : UITableViewController{
I have problem with context menu. I have got: @Override public void onCreateContextMenu(ContextMenu menu,
I have problem with php's preg_match.I want to make something like this : When
I have problem in my PHP code. I'm trying to make internet shop and

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.