Skip to content

[Android] Crash on app launch due to NullPointerException in UnityProxyActivity when social network extra is missing #84

@artyom-v

Description

@artyom-v

Some users experience a crash on app startup with the following exception:

Fatal Exception: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.xxx.xxx/com.xsolla.android.login.unity.UnityProxyActivity}: java.lang.NullPointerException
Caused by java.lang.NullPointerException:
       at com.xsolla.android.login.unity.UnityProxyActivity.onCreate(UnityProxyActivity.kt:20)

In UnityProxyActivity.onCreate(), the code retrieves the social network identifier using:

val socialNetworkString = intent.getStringExtra(ARG_SOCIAL_NETWORK)
val socialNetwork = SocialNetwork.valueOf(socialNetworkString!!)

If the Intent used to start UnityProxyActivity does not contain the ARG_SOCIAL_NETWORK extra, getStringExtra() returns null. The subsequent use of the not-null assertion operator (!!) causes a NullPointerException, crashing the app.

This can happen if:

  1. The activity is launched incorrectly (e.g., from an external source or deep link without required parameters).
  2. The Android system recreates the activity after process death without properly restoring the original intent.

Environment:
Unity version: 2022.3.62f2
Xsolla Store Unity SDK: v3.0.1

Suggested Fix:
Add null and validity checks before using the social network string:

val socialNetworkString = intent.getStringExtra(ARG_SOCIAL_NETWORK)
if (socialNetworkString == null) {
    finish()
    return
}
try {
    val socialNetwork = SocialNetwork.valueOf(socialNetworkString)
    // proceed with auth
} catch (e: IllegalArgumentException) {
    finish()
    return
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions