I have an activity, in its OnCreate:
serviceIntent = new Intent(this, MyServ.class);
int templen = myString.length();
Log.i("check", "mystring"+templen);
serviceIntent.putExtra("myString", myString);
startService(serviceIntent);
In the service,
public int onStartCommand(Intent intent, int flags, int startId) {
// TODO Auto-generated method stub
myString = intent.getExtras().getString("myString");
return START_STICKY;
}
It works fine. Then i opened many apps, to make android closes my app/services to free some ram. As you may expect, with START_STICKY, the service will try to restart, however, it failed to restart. The error log is:
Caused by: java.lang.NullPointerException at com.example.myapp.myserv.onStartCommand(MyServ.java:77), which points to this line:
myString = intent.getExtras().getString("myString");
So what i believe is there is no intent sent from myact when the service restarted. How should I handle this case? thanks