即使应用程序关闭,我也有一个在后台运行的服务。我从我开始服务的活动中传递了一些数据,我正在onStartCommand()
public int onStartCommand(Intent intent, int flags, int startId) {
Bundle extras = intent.getExtras();
if (extras != null) {
tstatus=extras.getString("status");
name=extras.getString("name");
dl_no=extras.getString("dl");
truck_id=extras.getString("tid");
latitude=extras.getString("lat");
longitude=extras.getString("lon");
}
但问题是当应用程序处于前台或最小化时它工作正常但是当我关闭应用程序时我的服务无法检索数据我得到以下错误:
java.lang.RuntimeException: Unable to start service com.example.grobomac.driver.CameraService@2ea3e490 with null:
java.lang.NullPointerException: Attempt to invoke virtual method 'android.os.Bundle android.content.Intent.getExtras()' on a null object reference
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'android.os.Bundle android.content.Intent.getExtras()' on a null object reference
at com.example.grobomac.driver.CameraService.onStartCommand(CameraService.java:176)