android - Converting my app to a service -


i've created geo-location app collects location information of device , compares pre-defined lat/long coordinates perform actions when match.

currently have activity page users can enter coordinates other parameters such radius , interval polling. also, app starts when user starts it.

i wish convert service following

  • runs in background
  • parameters read configuration file (this part done) hence no need main activity (no ui)
  • starts automatically (probably need android.intent.action.boot_completed broadcastreceiver)

how do this?

thanks.

you have create service application, this:

exampleservice.java:

public class exampleservice extends service {  @override public ibinder onbind(intent intent) {     // todo auto-generated method stub     return null; }    @override public void onstart(intent intent, int startid) {     // todo auto-generated method stub     super.onstart(intent, startid);      log.d(tag, "onstart()===>in");    // write application logical code here  }  @override public void ondestroy() {     // todo auto-generated method stub     super.ondestroy(); }  } 

bootcompletereceiver.java

public class bootcompletereceiver extends broadcastreceiver {  private static final string tag = "[bootcompletereceiver]";  @override public void onreceive(context context, intent intent) {     // todo auto-generated method stub     toast.maketext(context, "boot complete", toast.length_long).show();     log.d(tag, "boot complete");     // start exampleservice     intent service = new intent(context, exampleservice.class);     context.startservice(service); }  } 

in android manifest:

<!-- server service --> <service android:name="com.example.exampleservice" android:enabled="true" > </service>  <!-- boot complete receiver --> <receiver android:name="com.example.bootcompletereceiver" android:enabled="true" android:exported="true"> <intent-filter>     <action android:name="android.intent.action.boot_completed" /> </intent-filter> </receiver> 

you have create activity start service manually , awake service activity.


Comments

Popular posts from this blog

java - UnknownEntityTypeException: Unable to locate persister (Hibernate 5.0) -

python - ValueError: empty vocabulary; perhaps the documents only contain stop words -

ubuntu - collect2: fatal error: ld terminated with signal 9 [Killed] -