android: service with null intent
I have a widget that updates through a service whose onStart() references an Intent. After a period of using other applications, it seems as if the Android system restarts the service, presumably in some resource management capacity, leaving this intent null. In my onStart(), I am checking for null intent:
public void onStart(Intent intent, int startId){
if(intent != null){
//do stuff
} else {
System.out.println("service restarted");
}
}
But I am getting a nullPointerException on the conditional statement.
What is the correct way of dealing with this? The service is run from an alarm once per hour, so all it needs to do is run updateAppWidget when the system restarts it (I think...), but I'm not sure how to avoid this null pointer开发者_StackOverflow.
check whether did you pass a value on putString()
if not means it throws null pointer exceptions.
精彩评论