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 = {
                Media._ID,
                Media.TITLE,
        };

Cursor c = context.getContentResolver().query
( Media.EXTERNAL_CONTENT_URI,
cols,
Media.IS_MUSIC + " = 1",
null,
null);

--~--~---------~--~----~------------~-------~--~----~



Other Threads

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

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

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:

autenticator.xml:

<account-authenticator xmlns:android="http://schemas.android.com/apk/
res/android"
    android:accountType="typeOfAuthenticator"
    android:icon="@drawable/icon"
    android:smallIcon="@drawable/miniIcon"
    android:label="@string/label"
    android:accountPreferences="@xml/account_preferences"
 />

The Preference-Screen-xml looks like this:

account_preferences.xml:

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

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">
    <intent-filter>
     <action android:name="android.intent.action.VIEW" />
     <category android:name="android.intent.category.DEFAULT" />
    </intent-filter>
</activity>

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
mention.

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
--RKJ

-- 

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