Skip to content

Usage for Services

MarcinMoskala edited this page Feb 10, 2017 · 3 revisions

Usage for Services is pretty the same as [Activities](Usage for Activities) with following differences:

  • In generated class, there is no method for Service start. Only getIntent, which is standard way to provide Service intent.
  • Arguments also need to be filled, but there is no onCreate method. In should be done in onStartCommand method, and it needs both Service instance and intent, like in following code:
public class SomeService extends Service {

    @Arg String name;
    @Arg String surname;
    @Arg int id;

    public SomeService() {}

    @Override
    public IBinder onBind(Intent intent) {
        return null;
    }

    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
        ActivityStarter.fill(this, intent);
        //... Example: Log.i("SomeService", name + " " + surname + " " + id);
        return super.onStartCommand(intent, flags, startId);
    }
}

It also can be done in BaseService.