Deprecated Managedquery() Issue

Deprecated ManagedQuery() issue

You could replace it with context.getContentResolver().query and LoaderManager (you'll need to use the compatibility package to support devices before API version 11).

However, it looks like you're only using the query one time: you probably don't even need that. Maybe this would work?

public String getRealPathFromURI(Uri contentUri) {
String res = null;
String[] proj = { MediaStore.Images.Media.DATA };
Cursor cursor = getContentResolver().query(contentUri, proj, null, null, null);
if(cursor.moveToFirst()){;
int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
res = cursor.getString(column_index);
}
cursor.close();
return res;
}

What the appropriate replacer of deprecated managedQuery?

According to this great tutorial :

public class GridViewActivity extends FragmentActivity implements LoaderManager.LoaderCallbacks<Cursor>
{
private SimpleCursorAdapter mAdapter;

@Override
public Loader<Cursor> onCreateLoader(int p1, Bundle p2)
{
return new CursorLoader(this, Contacts.CONTENT_URI, null, null, null, Contacts.DISPLAY_NAME);
}

@Override
public void onLoadFinished(Loader<Cursor> p1, Cursor cursor)
{
mAdapter.swapCursor(cursor);
}

@Override
public void onLoaderReset(Loader<Cursor> cursor)
{
mAdapter.swapCursor(null);
}

@Override
protected void onCreate(Bundle savedInstanceState)
{
// TODO: Implement this method
super.onCreate(savedInstanceState);
setContentView(R.layout.gridview);
GridView gv = (GridView)findViewById(R.id.gridview);
String[] cols = new String[]{Contacts.DISPLAY_NAME};
int[] views = new int[]{android.R.id.text1};
mAdapter = new SimpleCursorAdapter(this, android.R.layout.simple_list_item_1, null, cols,views, 0);
gv.setAdapter(mAdapter);
getSupportLoaderManager().initLoader(0, null, this);
}

}

Deprecated ManagedQuery() issue in getting call logs

I found my answer here..

LoaderManager.LoaderCallbacks

Thanks everyone for the help!!!

Deprecated ManagedQuery() issue

You could replace it with context.getContentResolver().query and LoaderManager (you'll need to use the compatibility package to support devices before API version 11).

However, it looks like you're only using the query one time: you probably don't even need that. Maybe this would work?

public String getRealPathFromURI(Uri contentUri) {
String res = null;
String[] proj = { MediaStore.Images.Media.DATA };
Cursor cursor = getContentResolver().query(contentUri, proj, null, null, null);
if(cursor.moveToFirst()){;
int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
res = cursor.getString(column_index);
}
cursor.close();
return res;
}

Managed Query is not defined for service?

I am getting error that managedQuery is not define for Service

managedQuery() is a deprecated method on Activity.

Is there any way to do it in a service class as I want to make it work in the service class.

Call query() on a ContentResolver. You can get a ContentResolver by calling getContentResolver() on your Service. And, please call query() on a background thread, as it will involve disk I/O and IPC.

managedQuery() vs context.getContentResolver.query() vs android.provider.something.query()

managedQuery() will use ContentResolver's query(). The difference is
that with managedQuery() the activity will keep a reference to your
Cursor and close it whenever needed (in onDestroy() for instance.) If
you do query() yourself, you will have to manage the Cursor as a
sensitive resource. If you forget, for instance, to close() it in
onDestroy(), you will leak underlying resources (logcat will warn you
about it.)

To query a content provider, you can use either the ContentResolver.query() method or the Activity.managedQuery() method. Both methods take the same set of arguments, and both return a Cursor object. However, managedQuery() causes the activity to manage the life cycle of the Cursor. A managed Cursor handles all of the niceties, such as unloading itself when the activity pauses, and requerying itself when the activity restarts. You can ask an Activity to begin managing an unmanaged Cursor object for you by calling Activity.startManagingCursor().

Update:

managedQuery is now deprecated (as of Android 3.0).



Related Topics



Leave a reply



Submit