Android background Service crash while It swipe out

拈花ヽ惹草 提交于 2019-12-02 04:14:57
  1. void onStart(Intent intent, int startId) is deprecated, you need to use int onStartCommand(Intent intent, int flags, int startId) instead.
  2. onStart(...) is called from the onStartCommand(...) for backwards compatibility, and default implementation of the onStartCommand(...) returns the START_STICKY value. So, after the killing, yours service will be restarted by the system. When the service is restarted by the system, onStart(...) method can be called with a null intent object, and intent.getExtras().getString("user_Id") throws the NullPointerException, and service will be crashed, and restarted by the system...

As conclusion: you need to check the intent object for null befor using it.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!