ionic-team/ionic-portals

Crash when "startActivityForResult" and "Don't Keep Activity" setting is activated

cmveas opened this issue · 1 comments

I experienced this crash on a pet project I'm working on using ionic Portals. I have it when using a fragment that extends PortalFragment(but also happened in an activity that contains a portal in the layout). We use a library that internally does a call to startActivityForResult and the crash happens when the result is returned.

java.lang.NullPointerException
at io.ionic.portals.PortalFragment.load(PortalFragment.kt:99)
at io.ionic.portals.PortalFragment.onViewCreated(PortalFragment.kt:44)
at com.swisscom.myswisscom.activities.login.fragments.LoginFragment.onViewCreated(LoginFragment.kt:14)
at androidx.fragment.app.Fragment.performViewCreated(Fragment.java:2987)
at androidx.fragment.app.FragmentStateManager.createView(FragmentStateManager.java:546)
at androidx.fragment.app.FragmentStateManager.moveToExpectedState(FragmentStateManager.java:282)

In order to avoid the crash I used the following code but I think this might go into a place inside the PortalFragment implementation

class LoginFragment : PortalFragment {
    constructor() : super() {}
    constructor(portal: Portal?) : super(portal) {}

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        if (activity != null && portal!=null) {
            super.onViewCreated(view, savedInstanceState)
            setHasOptionsMenu(false)
        }
    }

I think the only check needed is the portal not being null

Thanks for reporting, the change I made should prevent the NPE from occurring. The fix will be in the next release