我正在使用branch.io
进行推荐。当我调用以使用loadRewards()
加载奖励时,我得到以下异常:
Fatal Exception: java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()
at android.os.Handler.(Handler.java:204)
at android.os.Handler.(Handler.java:118)
at io.branch.referral.InstallListener.captureInstallReferrer(InstallListener.java:56)
at io.branch.referral.Branch.registerAppInit(Branch.java:2340)
at io.branch.referral.Branch.initializeSession(Branch.java:2298)
at io.branch.referral.Branch.initUserSessionInternal(Branch.java:1286)
at io.branch.referral.Branch.handleNewRequest(Branch.java:2450)
at io.branch.referral.Branch.loadRewards(Branch.java:1699)
at com.musicmuni.riyaz.data.AppDataRepositoryImpl.getReferralCredits(AppDataRepositoryImpl.java:2926)
.......
查看错误消息,似乎需要从 UI 线程触发调用。但由于这是网络调用,这似乎不寻常。我错过了什么吗?
此崩溃仅在从非UI线程调用initSession时发生。您正在未调用 Looper.prepare(( 的线程中创建处理程序,因此您能否确保 initSession 发生在主线程上?