tags:

views:

18

answers:

1

I am doing some android application. I just wonder what will case the managedQuery method return a null value?

  if (getIntent().getData() == null) {
        getIntent().setData(Notepad.Notes.CONTENT_URI);
    }
    uri = getIntent().getData();
    c = managedQuery(uri, PROJECTION, null, null, null);// return null value. 
+1  A: 

managedQuery() will return null if any of the following are true:

  • The Uri supplied in the first parameter is null
  • The content provider implementation returned null as a result of the query
  • If an exception occurred when the content provider attempted to process the query

I really do not like your call to setData(). Please try something like:

Uri uri=getIntent().getData();

if (uri==null) {
  uri=Notepad.Notes.CONTENT_URI;
}

c=managedQuery(uri, PROJECTION, null, null, null);

This way, you know your Uri will not be null, so if you get null back from the managedQuery() call, your problem lies in the content provider.

CommonsWare
I like your coding style ... simple and easy to track....I have checked ... First parameter is not null.I am not sure if it is cased by the last two points..Thanks.
Russell Wong