Create a service:

[java]public class YourService extends Service {

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

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
// do your jobs here
return super.onStartCommand(intent, flags, startId);
}
}

[/java]

Create an Application class and start your service:

[java]

public class App extends Application {

@Override
public void onCreate() {
super.onCreate();

startService(new Intent(this, YourService.class));
}
}

[/java]

Don’t forget add this in “application” tag of your AndroidManifest.xml

[java]

android:name=".App"

[/java]

Leave a Reply

Your email address will not be published. Required fields are marked *