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    
 
About Chandana Nalin Cooray 75 Articles
Chandan is a tech enthusiast and digital strategist with over 5 years of experience in Artificial Intelligence and Software development. He specializes in simplifying complex tech trends for global audiences. When he’s not reviewing the latest AI tools, he shares his insights on future technology on chandanai.com. Follow him on LinkedIn for more tech updates