Pushwoosh.getInstance() error



当我尝试更新Pushwoosh库中的Pushwoosh应用程序时,我收到错误。我已经在 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) 

我在哪里得到错误

Pushwoosh.getInstance().registerForPushNotifications();

从Pushwoosh Github 复制响应:

这不是Pushwoosh SDK的错误。这是Android应用程序环境中多处理器应用程序的特殊性。

当您集成分析工具(如LeakCanary,AppMetrica等)时,这些库会为自己启动一个新过程。在此过程中创建应用的新实例。但是您不需要在这个单独的进程中侦听推送,因此默认情况下您不应该在Application.onCreate()中调用registerForPushNotifications()

因此,有两种可能的解决方案:

  • 不要在里面打电话给registerForPushNotificationsApplication.onCreate()

  • 如果要在 Application.onCreate() 中调用 registerForPushNotifications ,则应在应用程序的主进程中执行检查:

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; } } }

相关内容

  • 没有找到相关文章

最新更新