Services in Android

Spread the love
  • service is a component that runs in the background to perform long-running operations
  • To perform work for remote processes.
  • Runs in Background (No Interfaces)
Eg :com.android.music.MediaPlaybackService    
public class BackgroundSoundService extends Service { private static final String TAG = null; MediaPlayer player; public IBinder onBind(Intent arg0) { return null; } @Override public void onCreate() { super.onCreate(); player = MediaPlayer.create(this, R.raw.song); player.setLooping(true); // Set looping player.setVolume(100,100); } public int onStartCommand(Intent intent, int flags, int startId) { player.start(); return Service.START_STICKY; } @Override public void onDestroy() { player.stop(); player.release(); } }
6jfx33H