Why do I sometimes get a null return, from ContentResolver query?

by sandy8531 » Sun, 08 Mar 2009 09:56:01 GMT

Sponsored Links
 My external sdcard is connected, mounted and functional. I have over
1000 songs on the sdcard, however occasionally this query returns a
null Cursor to me.

Can someone shed some light as to why this happens ? Can I get this is
the underlying table is locked by another thread ? Should I take a
null return from the query to mean a temporary error ?

String[] cols = {

Cursor c = context.getContentResolver().query
Media.IS_MUSIC + " = 1",


Other Threads

1. PreferenceScreen - <intent 鈥? > - Exception - FLAG_ACTIVITY_NEW_TASK

I've got a probleme with an exception, but I don't know why I get this

The project is about implementing an AbstractAccountAuthenticator with
an AbstractThreadedSyncAdapter to sync certain data on a server with a
content provider.

I made everything and both adding accounts and syncing is running
without any problems.

Now I've tried to add a Preference-Screen just like suggested in the
android reference (search for AbstractAccountAuthenticator, it is
explained there) via xml like this:


<account-authenticator xmlns:android="http://schemas.android.com/apk/

The Preference-Screen-xml looks like this:


<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/
 <PreferenceCategory android:title="@string/pref_cat_general">
  <PreferenceScreen android:key="@string/pref_cat_scr_keygen"
   <intent android:action="android.intent.action.VIEW"
android:targetClass="com.android.clean.KeygenAct" />

The screen is promted how it should be, but and that is the problem:
When I click on the PreferenceScreen with the intent it leads to a
crash of the system (both in the emulator and my HTC-Desire).

Logcat says:

    ERROR/AndroidRuntime(18754): android.util.AndroidRuntimeException:
Calling startActivity() from outside of an Activity context requires
the FLAG_ACTIVITY_NEW_TASK flag. Is this really what you want?

(whole Logcat on pastebin: http://pastebin.com/cyzkwmYw)

Here the part of the manifest, where the activity is defined:

<activity android:name=".KeygenAct">
     <action android:name="android.intent.action.VIEW" />
     <category android:name="android.intent.category.DEFAULT" />

The whole test-code (it is my project on the essentials to find the
problem) is to find at googlecode (http://code.google.com/p/
cleanproject/source/browse/) (Eclipse-Project)

Thank you already for your help, Esentian

p.s.: keygen is not a key generator, it means more key_general. A bit
inartfully expressed ;)


2. How to calculate distance between to city (dynamically)

Hi All,

I want to calculate the distance between 2 city, whatever user

Example -
Default City - 1st City - New York or New Delhi, London Seoul anything
User Put     - 2nd City - California

Need - to calculate distance between California to New York  or London

Welcome any hints


3. Geocoder backend service

4. Activity throws an exception after the 1st run

5. Navigate up activity stack

6. Using a different layout depending on parent dimensions

7. Moved Android project to Eclipse 1.5 and new machine and project is missing Android jar