I have a BroadcastReceiver implementation that receives network connection events. its declared in the AndroidManifest.xml and is called by Android automatically when network events occur.
BroadcastReceiver:
public class ConnectivityChangeReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
Log.v(TAG, "action: " + intent.getAction());
Log.v(TAG, "component: " + intent.getComponent());
}
}
AndroidManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.test">
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
...
<receiver
android:name=".ConnectivityChangeReceiver"
android:enabled="true">
<intent-filter>
<action android:name="android.net.conn.CONNECTIVITY_CHANGE" />
</intent-filter>
</receiver>
</application>
</manifest>
I'd like to use Google's MVP sample architecture described here for my app:
https://github.com/googlesamples/android-architecture/tree/todo-mvp/
Using the above architecture, just wondering:
Where should my BroadcastReceiver be placed?
If my BroadcastReceiver needs to write to the database, whats the best way of doing this?
If my BroadcastReceiver needs to update the UI, whats the best way of doing this?