Question

This is a weird one,

When resuming an app from the launch icon in Android, I'm getting a crash on the version of my app on the Play Store.

This only occurs on some devices and ONLY on the version of the app on the Play Store - It doesn't even occur on the original APK uploaded to the Play Store.

The logging clearly shows the error is a NullPointerException occuring in onResume() when I'm trying to access a TextView created in onCreate()

My issue is, since I have no way of debugging the application (without uploading a new version of the App to the App store), I can't figure out if this is some sort of lifecycle error, or if the variable is being recycled when the Activity is destroyed.

Why is a View variable assigned during onCreate() becoming null in onResume()?

Edit

Since code was asked for - The Fragment is pretty large, so I've removed all code that doesn't reference the View. The variable mWifi is not accessed, referenced or assigned anywhere else in the file.

private TextView mWifi;

@Override
protected View onCreateView(LayoutInflater inflater, ViewGroup container, final Bundle savedInstanceState) { {
    View toReturn = inflater.inflate(R.layout.fragment_signin, null);

    mWifi = (TextView)toReturn.findViewById(R.id.wifi);

    return toReturn;
}

@Override
public void onResume() {    
    super.onResume();

    mWifi.setText(getWifiSSID(getActivity()));
}
Was it helpful?

Solution

As far as I can tell, this was being caused by two broadcasts being fired back to back.

In that instance, two Fragments were loaded at the exact same time.

I'm wondering if perhaps for some reason the Fragments were interfering with each other, as the life-cycle states for instantiation etc. would be almost synchronised but ever so slightly "off".

As of now, since I've fixed the problem by ensuring the broadcast happens only once, I'm assuming this is an OS bug caused from an Edge case scenario.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top