ANDROID App CRASH CRASHLYTICS LOG:
You can find the comment old code and the new added code from below snippet.
Send Broadcast(from Sender activity):
Deceleration in Receiver Activity or fragment:
in onCreate of Receiver Activity or fragment:
in OnPuase() method of Receiver Activity:
LocalBroadcastManager to send and receive broadcast in Android
Fatal Exception: android.app.RemoteServiceException
can't deliver broadcast
android.app.ActivityThread$H.handleMessage (ActivityThread.java:1867)
android.os.Handler.dispatchMessage (Handler.java:106)
android.os.Looper.loop (Looper.java:164)
android.app.ActivityThread.main (ActivityThread.java:6753)
java.lang.reflect.Method.invoke (Method.java)
com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:482)
com.android.internal.os.ZygoteInit.main (ZygoteInit.java:807)
This error: android.app.remoteserviceexception android 8 was first visible on my App on device ONEPLUS A5000 with Android 8.1 Oreocan't deliver broadcast
android.app.ActivityThread$H.handleMessage (ActivityThread.java:1867)
android.os.Handler.dispatchMessage (Handler.java:106)
android.os.Looper.loop (Looper.java:164)
android.app.ActivityThread.main (ActivityThread.java:6753)
java.lang.reflect.Method.invoke (Method.java)
com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:482)
com.android.internal.os.ZygoteInit.main (ZygoteInit.java:807)
You can find the comment old code and the new added code from below snippet.
Send Broadcast(from Sender activity):
try {
Intent broadcastIntent = new Intent();
broadcastIntent.setAction(mBroadcastStringAction);
// sendBroadcast(broadcastIntent); //old code to send broadcast
LocalBroadcastManager.getInstance(Application.get()).sendBroadcast(broadcastIntent);
}catch (Exception e){
e.printStackTrace();
}
Intent broadcastIntent = new Intent();
broadcastIntent.setAction(mBroadcastStringAction);
// sendBroadcast(broadcastIntent); //old code to send broadcast
LocalBroadcastManager.getInstance(Application.get()).sendBroadcast(broadcastIntent);
}catch (Exception e){
e.printStackTrace();
}
Deceleration in Receiver Activity or fragment:
//declared the intent filter and the broadcast receiver instance
private IntentFilter mIntentFilter;
//Brroadcast-Action-String decleration
public static final String mBroadcastStringAction = "com.example.apppackage.broadcast.string";
private BroadcastReceiver mReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
if (intent!=null && intent.getAction().equals(mBroadcastStringAction)) {
Log.e("BaseActivity","Your broadcast recived");
// set functionalities
}
}
};
private IntentFilter mIntentFilter;
//Brroadcast-Action-String decleration
public static final String mBroadcastStringAction = "com.example.apppackage.broadcast.string";
private BroadcastReceiver mReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
if (intent!=null && intent.getAction().equals(mBroadcastStringAction)) {
Log.e("BaseActivity","Your broadcast recived");
// set functionalities
}
}
};
in onCreate of Receiver Activity or fragment:
//define the intent filter action
mIntentFilter = new IntentFilter();
mIntentFilter.addAction(mBroadcastStringAction);
//register broadcast reciver
// getActivity().registerReceiver(mReceiver, mIntentFilter); // old code
LocalBroadcastManager.getInstance(Application.get()).registerReceiver(mReceiver, mIntentFilter);
mIntentFilter = new IntentFilter();
mIntentFilter.addAction(mBroadcastStringAction);
//register broadcast reciver
// getActivity().registerReceiver(mReceiver, mIntentFilter); // old code
LocalBroadcastManager.getInstance(Application.get()).registerReceiver(mReceiver, mIntentFilter);
in OnPuase() method of Receiver Activity:
//unregister broadcast reciver
// getActivity().unregisterReceiver(mReceiver); // old code
LocalBroadcastManager.getInstance(Application.get()).unregisterReceiver(mReceiver);
To find more on LocalBroadcastManager Refer:// getActivity().unregisterReceiver(mReceiver); // old code
LocalBroadcastManager.getInstance(Application.get()).unregisterReceiver(mReceiver);
LocalBroadcastManager to send and receive broadcast in Android
No comments:
Post a Comment