I m not able to get getSupportLoaderManger or getLoaderManager
I m confuse how to resolve this,
public class MyBroadCastReceiver extends BroadcastReceiver implements LoaderManager.LoaderCallbacks<Cursor> {
int cpValue;
private CursorLoader cursorLoader;
private Context mContext;
@Override
public void onReceive(Context context, Intent intent) {
mContext = context;
mContext.getSupportLoaderManager().initLoader(1, null, context);
}
private void doTheTask(MyAsync task, Intent intent) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
// Android 4.4 (API 19) and above
task.execute(intent);
} else {
// Android 3.0 to Android 4.3
task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, intent);
}
}
@Override
public Loader<Cursor> onCreateLoader(int arg0, Bundle arg1) {
cursorLoader = new CursorLoader(mContext, Uri.parse("content://com.MyApplication.Provider/cte"), null, null, null, null);
return cursorLoader;
}
@Override
public void onLoadFinished(Loader<Cursor> arg0, Cursor cursor) {
if (cursor != null) {
cursor.moveToFirst();
String res = "0";
while (!cursor.isAfterLast()) {
res = cursor.getString(cursor.getColumnIndex("present"));
cursor.moveToNext();
}
cpValue = Integer.valueOf(res);
} else {
cpValue = 0;
}
}
@Override
public void onLoaderReset(Loader<Cursor> arg0) {
}
}
My Question is So how can i use loaderManager in broadCast it is working fine in activity and fragment.
How Can I use LoaderManager inside the broadCast Receiver?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…