chat21 / chat21-android-sdk

Android Chat SDK built on Firebase
http://www.chat21.org
MIT License
233 stars 98 forks source link

ShutdownReceiver crash when phone runs out of battery, Android #36

Open ivankostadinovic opened 4 years ago

ivankostadinovic commented 4 years ago

Phone at 0% battery, shuts down, app crashes in the background because ChatManager.getInstance() causes a RuntimeException if the Instance is Null, doesn't return Null, so the code in ShutdownReceiver "onReceive" causes the app to crash:

@Override public void onReceive(Context context, Intent intent) { if (Intent.ACTION_SHUTDOWN.equals(intent.getAction())) { Log.i(TAG, "System shutting down");

        // disconnect the current user when the phone shutdown
        if(ChatManager.getInstance() != null) {
            ChatManager.getInstance().getMyPresenceHandler().dispose();
        }
    }
}

}

The crash: java.lang.RuntimeException: instance cannot be null. call start first. at org.chat21.android.core.ChatManager.getInstance(ChatManager.java:409) at org.chat21.android.core.receivers.ShutdownReceiver.onReceive(ShutdownReceiver.java:23)