I am getting this crash on a Nexus device (a Sony one with the same OS version does not crash):
02-20 14:38:14.551 22255 22255 I DebugActivity: java.lang.NullPointerException: Attempt to invoke virtual method 'android.os.Handler android.support.v4.app.FragmentHostCallback.getHandler()' on a null object reference
02-20 14:38:14.551 22255 22255 I DebugActivity: at android.support.v4.app.FragmentManagerImpl.ensureExecReady(FragmentManager.java:2180)
02-20 14:38:14.551 22255 22255 I DebugActivity: at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:2233)
02-20 14:38:14.551 22255 22255 I DebugActivity: at android.support.v4.app.FragmentController.execPendingActions(FragmentController.java:379)
02-20 14:38:14.551 22255 22255 I DebugActivity: at android.support.v4.app.FragmentActivity.onResume(FragmentActivity.java:461)
02-20 14:38:14.551 22255 22255 I DebugActivity: at com.whatever.sdk.MyActivity.onResume(MyActivity.java:109)
02-20 14:38:14.551 22255 22255 I DebugActivity: at com.whatever.sdk.MyActivity$1.onCallStateChanged(MyActivity.java:231)
02-20 14:38:14.551 22255 22255 I DebugActivity: at android.telephony.PhoneStateListener$2.handleMessage(PhoneStateListener.java:295)
02-20 14:38:14.551 22255 22255 I DebugActivity: at android.os.Handler.dispatchMessage(Handler.java:102)
02-20 14:38:14.551 22255 22255 I DebugActivity: at android.os.Looper.loop(Looper.java:148)
02-20 14:38:14.551 22255 22255 I DebugActivity: at android.app.ActivityThread.main(ActivityThread.java:5417)
02-20 14:38:14.551 22255 22255 I DebugActivity: at java.lang.reflect.Method.invoke(Native Method)
02-20 14:38:14.551 22255 22255 I DebugActivity: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
02-20 14:38:14.551 22255 22255 I DebugActivity: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
And here is the relevant piece of code:
public class MyActivity extends AppCompatActivity {
...
private final PhoneStateListener phoneStateListener = new PhoneStateListener() {
@Override
public void onCallStateChanged(int state, String incomingNumber) {
if(state == TelephonyManager.CALL_STATE_IDLE) {
MyActivity.this.onResume();
...
@Override
protected void onResume() {
try {
super.onResume();
...
The activity is not declared with any launchMode and trying to add different flags such as Intent.FLAG_ACTIVITY_CLEAR_TOP
when starting the activity did not help. We have supportLibraryVersion = '27.0.2'
Is there an obvious fix to this and why is it happening on some devices and not on others?
Credit to @ben-p's comment for the undocumented info on "only the Android framework should call [onResume()]" (mind you, this is a public method, along with onPostResume), the solution was to remove phoneStateListener
. Testing on the emulator, it is clear that the activity (and the video it hosts) is correctly paused and resumed by the framework when an incoming call notification is received and when the notification is dismissed or when the user finishes the phone call. The confusing part is that on most devices, calling onResume()
directly does not lead to a crash, hiding the bug.