i have a service getting started by Alarm Manager set to be repeated:
AlarmManager alarm = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
serviceSaveSample = new Intent(RunActivity.this,SaveSampleService.class);
alarmSaveSample = PendingIntent.getService(getApplicationContext(), 9988766, serviceSaveSample, PendingIntent.FLAG_CANCEL_CURRENT);
alarm.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + (secondsToSample*1000) , secondsToSample*1000, alarmSaveSample);
my onDestory function:
AlarmManager alarm = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
if(alarmSaveSample!=null)
alarm.cancel(alarmSaveSample);
if(alarmSendSample!=null)
alarm.cancel(alarmSendSample);
// stop services
if(serviceSendSample!=null)
stopService(serviceSendSample);
if(serviceSaveSample!=null)
stopService(serviceSaveSample);
super.onDestroy();
when i exit the app (by clearing it from memory in main screen) i get the error:
10-31 13:58:32.800: E/AndroidRuntime(24267):
java.lang.RuntimeException: Unable to start service
com.b2e.m2v.SaveSampleService@411b9ba8 with Intent { flg=0x4
cmp=com.b2e.m2v/.SaveSampleService (has extras) }:
java.lang.NullPointerException 10-31 13:58:32.800:
E/AndroidRuntime(24267): at
android.app.ActivityThread.handleServiceArgs(ActivityThread.java:2801)
10-31 13:58:32.800: E/AndroidRuntime(24267): at
android.app.ActivityThread.access$1900(ActivityThread.java:153) 10-31
13:58:32.800: E/AndroidRuntime(24267): at
android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
10-31 13:58:32.800: E/AndroidRuntime(24267): at
android.os.Handler.dispatchMessage(Handler.java:99) 10-31
13:58:32.800: E/AndroidRuntime(24267): at
android.os.Looper.loop(Looper.java:137) 10-31 13:58:32.800:
E/AndroidRuntime(24267): at
android.app.ActivityThread.main(ActivityThread.java:5227) 10-31
13:58:32.800: E/AndroidRuntime(24267): at
java.lang.reflect.Method.invokeNative(Native Method) 10-31
13:58:32.800: E/AndroidRuntime(24267): at
java.lang.reflect.Method.invoke(Method.java:511) 10-31 13:58:32.800:
E/AndroidRuntime(24267): at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:795)
10-31 13:58:32.800: E/AndroidRuntime(24267): at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:562) 10-31
13:58:32.800: E/AndroidRuntime(24267): at
dalvik.system.NativeStart.main(Native Method) 10-31 13:58:32.800:
E/AndroidRuntime(24267): Caused by: java.lang.NullPointerException
10-31 13:58:32.800: E/AndroidRuntime(24267): at
com.b2e.m2v.Controller.getLocation(Controller.java:75) 10-31
13:58:32.800: E/AndroidRuntime(24267): at
com.b2e.m2v.SaveSampleService.onStartCommand(SaveSampleService.java:35)
10-31 13:58:32.800: E/AndroidRuntime(24267): at
android.app.ActivityThread.handleServiceArgs(ActivityThread.java:2784)
10-31 13:58:32.800: E/AndroidRuntime(24267): ... 10 more
any idea why ?
maybe its important to say that this code run inside FragmentActivity