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
<activity
android:name=".activity.TransparentActivity"
android:theme="@style/Theme.Transparent">
</activity>
Style.xml
<style name="Theme.Transparent" parent="android:Theme">
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowBackground">@android:color/transparent</item>
<item name="android:windowContentOverlay">@null</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowIsFloating">true</item>
<item name="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;
public class TransparentActivity extends AppCompatActivity implements LoaderManager.LoaderCallbacks<Cursor> {
private CursorLoader cursorLoader;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getSupportLoaderManager().initLoader(1, null, this);
}
@Override
public Loader<Cursor> onCreateLoader(int arg0, Bundle arg1) {
cursorLoader = new CursorLoader(this, Uri.parse("content://com.example.yourprovider/cte"), null, null, null, null);
return cursorLoader;
}
@Override
public void onLoadFinished(Loader<Cursor> arg0, Cursor cursor) {
if (cursor != null) {
//Do your stuff
}
finish();
}
@Override
public void onLoaderReset(Loader<Cursor> arg0) {
}
}
So You will call this activity from the broadcast and it will going to update
Intent newIntent = new Intent(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?"