I Would Like To Use Loader Manager And Its Call Backs Inside Broadcast Receiver When Broadcast Fire?
I m not able to get getSupportLoaderManger or getLoaderManager I m confuse how to resolve this, public class MyBroadCastReceiver extends BroadcastReceiver implements LoaderManager
Solution 1:
Please, look at https://developer.android.com/reference/android/app/LoaderManager.html
LoaderManager is only used for Activity and Fragment
Solution 2:
For that One way is there you can go for the Transparent activity.
Manifest.xml
<activityandroid:name=".activity.TransparentActivity"android:theme="@style/Theme.Transparent"></activity>
Style.xml
<stylename="Theme.Transparent"parent="android:Theme"><itemname="android:windowIsTranslucent">true</item><itemname="android:windowBackground">@android:color/transparent</item><itemname="android:windowContentOverlay">@null</item><itemname="android:windowNoTitle">true</item><itemname="android:windowIsFloating">true</item><itemname="android:backgroundDimEnabled">false</item></style>
TransparentActivity.java
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.support.v4.app.LoaderManager;
import android.support.v4.content.CursorLoader;
import android.support.v4.content.Loader;
import android.support.v7.app.AppCompatActivity;
publicclassTransparentActivityextendsAppCompatActivityimplementsLoaderManager.LoaderCallbacks<Cursor> {
privateCursorLoader cursorLoader;
@OverrideprotectedvoidonCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getSupportLoaderManager().initLoader(1, null, this);
}
@OverridepublicLoader<Cursor> onCreateLoader(int arg0, Bundle arg1) {
cursorLoader = newCursorLoader(this, Uri.parse("content://com.example.yourprovider/cte"), null, null, null, null);
return cursorLoader;
}
@OverridepublicvoidonLoadFinished(Loader<Cursor> arg0, Cursor cursor) {
if (cursor != null) {
//Do your stuff
}
finish();
}
@OverridepublicvoidonLoaderReset(Loader<Cursor> arg0) {
}
}
So You will call this activity from the broadcast and it will going to update
Intent newIntent = newIntent(context,TransparentActivity.class);
newIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
newIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(newIntent);
So this will going to resolve your issues I hope so
This some how indirect way for this to achieve
Post a Comment for "I Would Like To Use Loader Manager And Its Call Backs Inside Broadcast Receiver When Broadcast Fire?"