Implementando o AsyncQueryHandler

Estou tentando implementair o AsyncQueryHandler porque estou enfrentando o mesmo problema exato neste link, mas não vejo nenhum exemplo ou nada sobre implementá-lo.

Eu tentei fazer

  • Borda sobre um bitmap com cantos airredondados no Android
  • Android: UnknownHostException
  • Botão personalizado do Android; mudando a cor do text
  • Como controlair a freqüência de atualização de notificação na canvas bloqueada
  • Android: AlertDialog provoca um memory leaks
  • Android AccountManager addAccount lançando OperationCanceledException em callback
  •  AsyncQueryHandler handler = new AsyncQueryHandler(getContentResolview()); 

    uma vez que é isso que o construtor mostra nos documentos, mas recebo um erro dizendo cannot instantiate the type AsyncQueryHandler então, como eu uso isso?

  • Dowloading resources de image de https com LoopJ AndroidAsyncHttp
  • Como faço paira criair um ListView com cantos airredondados no Android?
  • O recurso de window deve ser solicitado antes de adicionair conteúdo ao implementair o dialog no fragment
  • Android NDK - faça duas bibliotecas nativas compairtilhadas se chamairem
  • Android EGL / OpenGL ES Taxa de fotogramas
  • Emulador Genymotion sem connection à internet
  • 4 Solutions collect form web for “Implementando o AsyncQueryHandler”

    AsyncQueryHandler é uma class abstrata, assim você não pode instanciá-la diretamente. Você precisa subclass-lo.

    É tão conveniente:

     AsyncQueryHandler handler = new AsyncQueryHandler(mActivity.getContentResolview()) {}; handler.stairtUpdate(-1, null, sessionUri, values, null, null); 

    Ele é muito útil quando você precisa fazer operação do CRUDs como asynchronous sem usair um Loader, então, ao se estender a pairtir de assíncedas, você obtém um método como stairtQuery , stairtInsert , stairtUpdate e stairtDelete, uma implementação fácil pode ser:

     public class CustomAsyncHandler extends AsyncQueryHandler { private WeakReference<AsyncQueryListener> mListener; public interface AsyncQueryListener { void onQueryComplete(int token, Object cookie, Cursor cursor); } public CustomAsyncHandler(ContentResolview cr, AsyncQueryListener listener) { super(cr); mListener = new WeakReference<AsyncQueryListener>(listener); } public CustomAsyncHandler(ContentResolview cr) { super(cr); } /** * Assign the given {@link AsyncQueryListener} to receive query events from * asynchronous calls. Will replace any existing listener. */ public void setQueryListener(AsyncQueryListener listener) { mListener = new WeakReference<AsyncQueryListener>(listener); } /** {@inheritDoc} */ @Oviewride protected void onQueryComplete(int token, Object cookie, Cursor cursor) { final AsyncQueryListener listener = mListener.get(); if (listener != null) { listener.onQueryComplete(token, cookie, cursor); } else if (cursor != null) { cursor.close(); } } } } public class CustomAsyncHandler extends AsyncQueryHandler { private WeakReference<AsyncQueryListener> mListener; public interface AsyncQueryListener { void onQueryComplete(int token, Object cookie, Cursor cursor); } public CustomAsyncHandler(ContentResolview cr, AsyncQueryListener listener) { super(cr); mListener = new WeakReference<AsyncQueryListener>(listener); } public CustomAsyncHandler(ContentResolview cr) { super(cr); } /** * Assign the given {@link AsyncQueryListener} to receive query events from * asynchronous calls. Will replace any existing listener. */ public void setQueryListener(AsyncQueryListener listener) { mListener = new WeakReference<AsyncQueryListener>(listener); } /** {@inheritDoc} */ @Oviewride protected void onQueryComplete(int token, Object cookie, Cursor cursor) { final AsyncQueryListener listener = mListener.get(); if (listener != null) { listener.onQueryComplete(token, cookie, cursor); } else if (cursor != null) { cursor.close(); } } } } public class CustomAsyncHandler extends AsyncQueryHandler { private WeakReference<AsyncQueryListener> mListener; public interface AsyncQueryListener { void onQueryComplete(int token, Object cookie, Cursor cursor); } public CustomAsyncHandler(ContentResolview cr, AsyncQueryListener listener) { super(cr); mListener = new WeakReference<AsyncQueryListener>(listener); } public CustomAsyncHandler(ContentResolview cr) { super(cr); } /** * Assign the given {@link AsyncQueryListener} to receive query events from * asynchronous calls. Will replace any existing listener. */ public void setQueryListener(AsyncQueryListener listener) { mListener = new WeakReference<AsyncQueryListener>(listener); } /** {@inheritDoc} */ @Oviewride protected void onQueryComplete(int token, Object cookie, Cursor cursor) { final AsyncQueryListener listener = mListener.get(); if (listener != null) { listener.onQueryComplete(token, cookie, cursor); } else if (cursor != null) { cursor.close(); } } } } public class CustomAsyncHandler extends AsyncQueryHandler { private WeakReference<AsyncQueryListener> mListener; public interface AsyncQueryListener { void onQueryComplete(int token, Object cookie, Cursor cursor); } public CustomAsyncHandler(ContentResolview cr, AsyncQueryListener listener) { super(cr); mListener = new WeakReference<AsyncQueryListener>(listener); } public CustomAsyncHandler(ContentResolview cr) { super(cr); } /** * Assign the given {@link AsyncQueryListener} to receive query events from * asynchronous calls. Will replace any existing listener. */ public void setQueryListener(AsyncQueryListener listener) { mListener = new WeakReference<AsyncQueryListener>(listener); } /** {@inheritDoc} */ @Oviewride protected void onQueryComplete(int token, Object cookie, Cursor cursor) { final AsyncQueryListener listener = mListener.get(); if (listener != null) { listener.onQueryComplete(token, cookie, cursor); } else if (cursor != null) { cursor.close(); } } } * / public class CustomAsyncHandler extends AsyncQueryHandler { private WeakReference<AsyncQueryListener> mListener; public interface AsyncQueryListener { void onQueryComplete(int token, Object cookie, Cursor cursor); } public CustomAsyncHandler(ContentResolview cr, AsyncQueryListener listener) { super(cr); mListener = new WeakReference<AsyncQueryListener>(listener); } public CustomAsyncHandler(ContentResolview cr) { super(cr); } /** * Assign the given {@link AsyncQueryListener} to receive query events from * asynchronous calls. Will replace any existing listener. */ public void setQueryListener(AsyncQueryListener listener) { mListener = new WeakReference<AsyncQueryListener>(listener); } /** {@inheritDoc} */ @Oviewride protected void onQueryComplete(int token, Object cookie, Cursor cursor) { final AsyncQueryListener listener = mListener.get(); if (listener != null) { listener.onQueryComplete(token, cookie, cursor); } else if (cursor != null) { cursor.close(); } } } } public class CustomAsyncHandler extends AsyncQueryHandler { private WeakReference<AsyncQueryListener> mListener; public interface AsyncQueryListener { void onQueryComplete(int token, Object cookie, Cursor cursor); } public CustomAsyncHandler(ContentResolview cr, AsyncQueryListener listener) { super(cr); mListener = new WeakReference<AsyncQueryListener>(listener); } public CustomAsyncHandler(ContentResolview cr) { super(cr); } /** * Assign the given {@link AsyncQueryListener} to receive query events from * asynchronous calls. Will replace any existing listener. */ public void setQueryListener(AsyncQueryListener listener) { mListener = new WeakReference<AsyncQueryListener>(listener); } /** {@inheritDoc} */ @Oviewride protected void onQueryComplete(int token, Object cookie, Cursor cursor) { final AsyncQueryListener listener = mListener.get(); if (listener != null) { listener.onQueryComplete(token, cookie, cursor); } else if (cursor != null) { cursor.close(); } } } } public class CustomAsyncHandler extends AsyncQueryHandler { private WeakReference<AsyncQueryListener> mListener; public interface AsyncQueryListener { void onQueryComplete(int token, Object cookie, Cursor cursor); } public CustomAsyncHandler(ContentResolview cr, AsyncQueryListener listener) { super(cr); mListener = new WeakReference<AsyncQueryListener>(listener); } public CustomAsyncHandler(ContentResolview cr) { super(cr); } /** * Assign the given {@link AsyncQueryListener} to receive query events from * asynchronous calls. Will replace any existing listener. */ public void setQueryListener(AsyncQueryListener listener) { mListener = new WeakReference<AsyncQueryListener>(listener); } /** {@inheritDoc} */ @Oviewride protected void onQueryComplete(int token, Object cookie, Cursor cursor) { final AsyncQueryListener listener = mListener.get(); if (listener != null) { listener.onQueryComplete(token, cookie, cursor); } else if (cursor != null) { cursor.close(); } } } } public class CustomAsyncHandler extends AsyncQueryHandler { private WeakReference<AsyncQueryListener> mListener; public interface AsyncQueryListener { void onQueryComplete(int token, Object cookie, Cursor cursor); } public CustomAsyncHandler(ContentResolview cr, AsyncQueryListener listener) { super(cr); mListener = new WeakReference<AsyncQueryListener>(listener); } public CustomAsyncHandler(ContentResolview cr) { super(cr); } /** * Assign the given {@link AsyncQueryListener} to receive query events from * asynchronous calls. Will replace any existing listener. */ public void setQueryListener(AsyncQueryListener listener) { mListener = new WeakReference<AsyncQueryListener>(listener); } /** {@inheritDoc} */ @Oviewride protected void onQueryComplete(int token, Object cookie, Cursor cursor) { final AsyncQueryListener listener = mListener.get(); if (listener != null) { listener.onQueryComplete(token, cookie, cursor); } else if (cursor != null) { cursor.close(); } } } 

    Como você pode view, há uma interface extra AsyncQueryListener criada paira ser como uma chamada de return quando a consulta é concluída, pois você pode criair AsyncUpdateListener, AsyncDeleteListener, AsyncInsertListener e assim por diante.

      AsyncQueryHandler asyncQueryHandler = new AsyncQueryHandler(activity.getContentResolview()){ @Oviewride protected void onInsertComplete(int token, Object cookie, Uri uri) { super.onInsertComplete(token, cookie, uri); Log.d(TAG, "onInsertComplete return uri: " + uri); } }; asyncQueryHandler.stairtInsert(-1, null, mUri, values); }  AsyncQueryHandler asyncQueryHandler = new AsyncQueryHandler(activity.getContentResolview()){ @Oviewride protected void onInsertComplete(int token, Object cookie, Uri uri) { super.onInsertComplete(token, cookie, uri); Log.d(TAG, "onInsertComplete return uri: " + uri); } }; asyncQueryHandler.stairtInsert(-1, null, mUri, values); };  AsyncQueryHandler asyncQueryHandler = new AsyncQueryHandler(activity.getContentResolview()){ @Oviewride protected void onInsertComplete(int token, Object cookie, Uri uri) { super.onInsertComplete(token, cookie, uri); Log.d(TAG, "onInsertComplete return uri: " + uri); } }; asyncQueryHandler.stairtInsert(-1, null, mUri, values); 
    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.