Ahmet Kocaman
Ahmet Kocaman

Reputation: 109

Pushwoosh.getInstance() error

I am getting an error when I try to update my pushwoosh applications in the Pushwoosh library.I've updated it in Gradle.

07-06 18:21:59.637 19950-19950/com.ahmet.sen E/AndroidRuntime: FATAL EXCEPTION: main
                                                              Process: com.ahmet.sen, PID: 19950
                                                              java.lang.ExceptionInInitializerError
                                                                  at com.ahmet.sen.MainActivity.onCreate(MainActivity.java:50)
                                                                  at android.app.Activity.performCreate(Activity.java:6237)
                                                                  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)
                                                                  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)
                                                                  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
                                                                  at android.app.ActivityThread.-wrap11(ActivityThread.java)
                                                                  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
                                                                  at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                  at android.os.Looper.loop(Looper.java:148)
                                                                  at android.app.ActivityThread.main(ActivityThread.java:5417)
                                                                  at java.lang.reflect.Method.invoke(Native Method)
                                                                  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
                                                                  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
                                                               Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'com.pushwoosh.notification.j com.pushwoosh.c.d()' on a null object reference
                                                                  at com.pushwoosh.Pushwoosh.<init>(Unknown Source)
                                                                  at com.pushwoosh.Pushwoosh.<clinit>(Unknown Source)
                                                                  at com.ahmet.sen.MainActivity.onCreate(MainActivity.java:50) 
                                                                  at android.app.Activity.performCreate(Activity.java:6237) 
                                                                  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107) 
                                                                  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369) 
                                                                  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) 
                                                                  at android.app.ActivityThread.-wrap11(ActivityThread.java) 
                                                                  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) 
                                                                  at android.os.Handler.dispatchMessage(Handler.java:102) 
                                                                  at android.os.Looper.loop(Looper.java:148) 
                                                                  at android.app.ActivityThread.main(ActivityThread.java:5417) 
                                                                  at java.lang.reflect.Method.invoke(Native Method) 
                                                                  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
                                                                  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 

Where i get the error

        Pushwoosh.getInstance().registerForPushNotifications();

Upvotes: 0

Views: 243

Answers (1)

WFHM
WFHM

Reputation: 81

Duplicating response from Pushwoosh Github here:

This is not a bug of Pushwoosh SDK. This is a peculiarity of multi-processor applications in Android apps environment.

When you integrate analytics tools such as LeakCanary, AppMetrica, and others, these libraries start a new process for itself. A new instance of the app is created In this process. But you do not need to listen for pushes in this separate process, so by default you should not call registerForPushNotifications() inside Application.onCreate().

Therefore there are 2 possible solutions:

  • Not to call registerForPushNotifications inside Application.onCreate()

  • If you want to call registerForPushNotifications inside Application.onCreate(), you should perform a check in application's main process:

List < ActivityManager.RunningAppProcessInfo > runningAppProcesses = ((ActivityManager) getSystemService(Context.ACTIVITY_SERVICE)).getRunningAppProcesses(); if (runningAppProcesses != null && runningAppProcesses.size() != 0) { for (ActivityManager.RunningAppProcessInfo runningAppProcessInfo: runningAppProcesses) { boolean isCurrentProcess = runningAppProcessInfo.pid == android.os.Process.myPid(); boolean isMainProcessName = getPackageName().equals(runningAppProcessInfo.processName); if (isCurrentProcess && isMainProcessName) { Pushwoosh.getInstance().registerForPushNotifications(...); break; } } }

Upvotes: 0

Related Questions