qiscus / qiscus-sdk-android

Qiscus provide everything you need to power up your app with chats. And it's now made simple.
https://www.qiscus.com
Apache License 2.0
201 stars 84 forks source link

Force close on notification click #11

Closed mahasadhu closed 7 years ago

mahasadhu commented 7 years ago

Hello, I just try to create a simple app using qiscus.

When I click on the new chat notification, the app always force closed. The logcat says that the app did not call the setuser method, although it did call the setuser method. Besides, how could the app receive a notification if the setuser method is not called yet ?

I use sdk ver 2.7.2 error happened in android 6 and 7

Following is the error log. Thank you in advance.

FATAL EXCEPTION: main Process: com.mahasadhu.testchat, PID: 3860 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.mahasadhu.testchat/com.qiscus.sdk.ui.QiscusChatActivity}: java.lang.RuntimeException: Please set Qiscus user before start the chatting! at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2646) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2707) at android.app.ActivityThread.-wrap12(ActivityThread.java) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1460) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:154) at android.app.ActivityThread.main(ActivityThread.java:6077) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755) Caused by: java.lang.RuntimeException: Please set Qiscus user before start the chatting! at com.qiscus.sdk.Qiscus.checkUserSetup(Qiscus.java:425) at com.qiscus.sdk.Qiscus.getQiscusAccount(Qiscus.java:224) at com.qiscus.sdk.ui.QiscusChatActivity.onViewReady(QiscusChatActivity.java:87) at com.qiscus.sdk.ui.QiscusBaseChatActivity.onCreate(QiscusBaseChatActivity.java:85) at android.app.Activity.performCreate(Activity.java:6662) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2599) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2707)  at android.app.ActivityThread.-wrap12(ActivityThread.java)  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1460)  at android.os.Handler.dispatchMessage(Handler.java:102)  at android.os.Looper.loop(Looper.java:154)  at android.app.ActivityThread.main(ActivityThread.java:6077)  at java.lang.reflect.Method.invoke(Native Method)  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865)  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755) 

zetbaitsu commented 7 years ago

Can you show me the code how do you call the Qiscus.setUser method? And please make sure your application is not logged out after getting push notification. These exceptions will only be thrown if Qiscus does not find any account information, but your application tries to perform tasks that require a Qiscus account.

mahasadhu commented 7 years ago

Hi, I have fixed the problem myself, so it seems like when the user click on the notification, all other activity is destroyed. I put clearuser in ondestroy method. And that's where the problem is.

By the way I guess you should try to not make it force closed when the app forgets to set or do something to the sdk. Just my two cents though 😃

Anyway thanks for the reply and instructions !

zetbaitsu commented 7 years ago

Please note Qiscus.clearUser is only used when user wants to logout from Qiscus. Do not call every time Actcivity is destroyed, but call when the user logs out of his account.

It should be force close by design, you can not use any feature before setting qiscus user.

mahasadhu commented 7 years ago

Yep I got it, thank you