Saturday, 15 September 2012

android - Service closes when I clear app History by Long Pressing Home key -



android - Service closes when I clear app History by Long Pressing Home key -

i launching service activity. service runs countdown timer launch ads.

but when clears apps history long pressing home key forcefulness stop app @ line checking intent extras.

it gives null pointer exception @ line below,

public int onstartcommand(intent intent, int flags, int startid) { if (intent.getextras() != null && intent.hasextra("type")) // <== npe @ line type = intent.getextras().getstring("type"); . . . }

as can see tried check if intent null intent.getextras() != null still gives npe , forcefulness closes app.

why onstartcommand called when clear history , countdown timer finishes , launch other activity, launches service afterwards.

logcat :

java.lang.runtimeexception: unable start service com.main.example.adservice null: java.lang.nullpointerexception 06-23 13:58:05.004: e/androidruntime(12667): @ android.app.activitythread.handleserviceargs(activitythread.java:2660) 06-23 13:58:05.004: e/androidruntime(12667): @ android.app.activitythread.access$1900(activitythread.java:149) 06-23 13:58:05.004: e/androidruntime(12667): @ android.app.activitythread$h.handlemessage(activitythread.java:1402) 06-23 13:58:05.004: e/androidruntime(12667): @ android.os.handler.dispatchmessage(handler.java:99) 06-23 13:58:05.004: e/androidruntime(12667): @ android.os.looper.loop(looper.java:153) 06-23 13:58:05.004: e/androidruntime(12667): @ android.app.activitythread.main(activitythread.java:5000) 06-23 13:58:05.004: e/androidruntime(12667): @ java.lang.reflect.method.invokenative(native method) 06-23 13:58:05.004: e/androidruntime(12667): @ java.lang.reflect.method.invoke(method.java:511) 06-23 13:58:05.004: e/androidruntime(12667): @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:821) 06-23 13:58:05.004: e/androidruntime(12667): @ com.android.internal.os.zygoteinit.main(zygoteinit.java:584) 06-23 13:58:05.004: e/androidruntime(12667): @ dalvik.system.nativestart.main(native method) 06-23 13:58:05.004: e/androidruntime(12667): caused by: java.lang.nullpointerexception 06-23 13:58:05.004: e/androidruntime(6295): com.main.example.adservice.onstartcommand(adservice.java:83) 06-23 13:58:05.004: e/androidruntime(12667): @ android.app.activitythread.handleserviceargs(activitythread.java:2643)

the intent null. expected behavior start_sticky, when android restarts service, noted in the documentation start_sticky.

android android-intent android-service

No comments:

Post a Comment