''android.app.ActivityThread$ApplicationThread android.app.ActivityThread.getApplicationThread()' on a null object reference

I am trying to show the native phone number hint pop up from unity, but I keep getting the below exception. java.lang.NullPointerException: Attempt to invoke virtual method 'android.app.ActivityThread$ApplicationThread android.app.ActivityThread.getApplicationThread()' on a null object reference

Here is my Java code

package com.manish.unity;


import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.widget.Toast;

import com.google.android.gms.auth.api.Auth;
import com.google.android.gms.auth.api.credentials.Credential;
import com.google.android.gms.auth.api.credentials.HintRequest;
import com.google.android.gms.common.api.GoogleApiClient;
import com.unity3d.player.UnityPlayer;


public class NativePhoneNumberPlugin extends UnityPlayerActivity {
    private static final NativePhoneNumberPlugin ourInstance = new NativePhoneNumberPlugin();

    private static final String LOGTAG = "manish";

    public static NativePhoneNumberPlugin getInstance() {return ourInstance;}

    private int RESOLVE_HINT;
    private GoogleApiClient googleApiClient;
    private Context context;

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Log.i(LOGTAG, "Called OnCreate");
        context = UnityPlayer.currentActivity;
        Toast.makeText(context, "OnCreate called", Toast.LENGTH_SHORT).show();

    }

    public void ShowMessage(String message)
    {
        Log.i(LOGTAG,"Called Show message");
        Toast.makeText(UnityPlayer.currentActivity, message, Toast.LENGTH_SHORT).show();
    }

    public void requestPhoneNumber() {
        Log.i(LOGTAG,"Request phone number called1");
        if(googleApiClient == null)
        {
            googleApiClient = new GoogleApiClient.Builder(UnityPlayer.currentActivity)
                    .addApi(Auth.CREDENTIALS_API)
                    .build();
        }
        HintRequest hintRequest = new HintRequest.Builder()
                .setPhoneNumberIdentifierSupported(true)
                .build();

        PendingIntent intent = Auth.CredentialsApi.getHintPickerIntent(
                googleApiClient, hintRequest);
        if(intent == null)
        {
            Log.i(LOGTAG,"Intent is NULL");
        }
        else
        {
            Log.i(LOGTAG,"NOT NULL INTENT");
        }
        try
        {
            startIntentSenderForResult(intent.getIntentSender(),RESOLVE_HINT, null, 0,0,0);
        }
        catch (Exception e)
        {
            Log.i(LOGTAG,"Exception caught"+e.toString());
        }
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == RESOLVE_HINT) {
            if (resultCode == RESULT_OK) {
                Credential cred = data.getParcelableExtra(com.google.android.gms.auth.api.credentials.Credential.EXTRA_KEY);
                System.out.println("OnActivity Result");
            }
            else
            {
                Toast.makeText(context, "No Phone numbers found "+resultCode, Toast.LENGTH_SHORT).show();
            }
        }
    }
}


Solution 1:[1]

I was able to solve the issue. In my case, the problem was in the try block

        {
            startIntentSenderForResult(intent.getIntentSender(),RESOLVE_HINT, null, 0,0,0);
        }```

the Activity was null for me, to fix this I just replaced the above block of code with the following

```try
        {
            UnityPlayer.currentActivity.startIntentSenderForResult(intent.getIntentSender(),RESOLVE_HINT, null, 0,0,0);
        }```

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Manish kumar