android service is NullPointerException -
android service is NullPointerException -
who can help me? why bindservice() on onresume() of activity create? how command create in date of bindservice()? please help solve below query. utilize bindservice() method after bindservice(),
private testservice ts; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); system.out.println("serviceactivity oncreate()"); bindservice(new intent(this, testservice.class), conn, bind_auto_create); ts.setnum(0);//here throw nullpointerexception } private serviceconnection conn = new serviceconnection() { @override public void onservicedisconnected(componentname name) { } @override public void onserviceconnected(componentname name, ibinder service) { ts = ((mybinder)service).getservice(); } };
androidmanifest.xml
<activity android:name=".serviceactivity" android:label="serviceactivity"> <intent-filter> <action android:name="android.intent.action.main" /> <category android:name="android.intent.category.launcher" /> </intent-filter> </activity> <service android:name="org.caau.android.service.testservice"> </service>
i'm not expert in bindservice thing went android developer website , read some.
as far can see you're missing in manifest file services. --- website --- global access service can enforced when declared in manifest's tag. doing so, other applications need declare corresponding element in own manifest able start, stop, or bind service.
in addition, service can protect individual ipc calls permissions, calling checkcallingpermission(string) method before executing implementation of call.
see security , permissions document more info on permissions , security in general. --- website ---
since i'm not sure rest of code suggest should @ examples android provides here local service sample
or can debug yourself. set logs in onserviceconnected, , before ts.setnum
android android-service
Comments
Post a Comment