Skip to content

Commit 804fd18

Browse files
authored
Merge pull request #645 from Kommunicate-io/Fix_NullPointerException_Crash
Proactive checks before starting services
2 parents 735efce + e1edce6 commit 804fd18

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

kommunicate/src/main/java/io/kommunicate/devkit/api/conversation/ChatIntentService.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,14 @@ public void onCreate() {
4848

4949
@Override
5050
protected void onHandleWork(@NonNull Intent intent) {
51+
52+
// If the service is started by the system before a user has logged in,
53+
// the SDK won't have the necessary credentials. Abort early to prevent crashes.
54+
if (!MobiComUserPreference.getInstance(this).isLoggedIn()) {
55+
Utils.printLog(this, "ChatIntentService", "Service triggered, but user is not logged in. Aborting work.");
56+
return;
57+
}
58+
5159
boolean connectivityChange = intent.getBooleanExtra(AL_SYNC_ON_CONNECTIVITY, false);
5260
boolean timeChangeReceiver = intent.getBooleanExtra(AL_TIME_CHANGE_RECEIVER, false);
5361

0 commit comments

Comments
 (0)