đ Android Foreground Service – āĻŦ্āϰেāĻāύ-āĻĢ্āϰেāύ্āĻĄāϞি āĻāĻ্āϏāĻĒ্āϞাāύেāĻļāύ!
đ Android Foreground Service – āĻŦ্āϰেāĻāύ-āĻĢ্āϰেāύ্āĻĄāϞি āĻāĻ্āϏāĻĒ্āϞাāύেāĻļāύ! đ¯
āĻāĻĒāύি āύিāĻļ্āĻā§āĻ āĻেā§াāϞ āĻāϰেāĻেāύ—
- YouTube Music đĩ āĻŦ্āϝাāĻāĻ্āϰাāĻāύ্āĻĄে āĻাāύ āĻŦাāĻিā§ে āϝাāĻ্āĻে!
- Google Maps đē️ āϏ্āĻ্āϰিāύ āĻŦāύ্āϧ āĻĨাāĻāϞেāĻ āϞোāĻেāĻļāύ āĻ্āϰ্āϝাāĻ āĻāϰāĻে!
- WhatsApp Call đ āϏ্āĻ্āϰিāύেāϰ āĻāĻĒāϰ āĻোāĻ্āĻ āύোāĻিāĻĢিāĻেāĻļāύ āĻĻেāĻাāĻ্āĻে!
đ āĻāĻুāϞো āϏāĻŦ Foreground Service āĻŦ্āϝāĻŦāĻšাāϰ āĻāϰে! đ˛
đ Foreground Service āĻী?
āĻāĻāĻা āϏাāϧাāϰāĻŖ Service āĻŦ্āϝাāĻāĻ্āϰাāĻāύ্āĻĄে āĻুāĻĒāĻাāĻĒ āĻাāĻ āĻāϰে đ¤,
āĻিāύ্āϤু Foreground Service Active āĻাāĻŦে āĻāĻāĻাāϰāĻে āĻাāύিā§ে āĻাāĻ āĻাāϞিā§ে āϝাā§! đĨ
✅ āĻāĻ āϏাāϰ্āĻিāϏ āϏāĻŦāϏāĻŽā§ āĻāĻāĻাāϰেāϰ āϏাāĻŽāύে (Foreground) āĻĨেāĻে āĻাāĻ āĻāϰে!
✅ āĻāĻা āĻŦāύ্āϧ āύা āĻāϰা āĻĒāϰ্āϝāύ্āϤ āĻাāĻ āĻাāϞিā§ে āϝাā§!
✅ āĻāĻা āĻŦ্āϝাāĻāĻ্āϰাāĻāύ্āĻĄে āĻাāĻ āĻāϰāϞেāĻ āĻāĻāĻাāϰāĻে āύোāĻিāĻĢিāĻেāĻļāύ āĻĻেāĻাā§!
đ¯ āĻāĻĻাāĻšāϰāĻŖ:
- Spotify āĻŦা YouTube Music āĻাāύ āĻŦাāĻাāĻ্āĻে đĩ
- Google Maps āϞোāĻেāĻļāύ āĻ্āϰ্āϝাāĻ āĻāϰāĻে đē️
- WhatsApp Call āĻāϞāĻে đ
- Download Progress āĻĻেāĻাāύো āĻšāĻ্āĻে đĨ
đ ️ Foreground Service āĻীāĻাāĻŦে āĻাāĻ āĻāϰে?
đĄ Step 1: āϏাāϧাāϰāĻŖ Service āϤৈāϰি āĻāϰা!
đĄ Step 2: Foreground Service-āĻ āϰূāĻĒাāύ্āϤāϰ āĻāϰা!
đĄ Step 3: āϏাāϰ্āĻিāϏেāϰ āϏাāĻĨে āύোāĻিāĻĢিāĻেāĻļāύ āϝুāĻ্āϤ āĻāϰা!
đ Foreground Service-āĻāϰ āĻāύ্āϝ āύোāĻিāĻĢিāĻেāĻļāύ āĻŦাāϧ্āϝāϤাāĻŽূāϞāĻ!
đ¨đģ āĻোāĻĄ āĻĻিā§ে Foreground Service āϤৈāϰি āĻāϰা!
1️⃣ Service āϤৈāϰি āĻāϰা
class MyForegroundService : Service() {
override fun onCreate() {
super.onCreate()
Log.d("ForegroundService", "Service Created")
}
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
val notification = createNotification()
startForeground(1, notification) // Foreground Service āĻাāϞু āĻāϰāϞাāĻŽ
return START_STICKY
}
override fun onDestroy() {
super.onDestroy()
Log.d("ForegroundService", "Service Stopped")
}
override fun onBind(intent: Intent?): IBinder? {
return null
}
private fun createNotification(): Notification {
val channelId = "ForegroundServiceChannel"
val notificationBuilder = NotificationCompat.Builder(this, channelId)
.setContentTitle("Foreground Service Running")
.setContentText("This service is running in the foreground.")
.setSmallIcon(R.drawable.ic_notification)
return notificationBuilder.build()
}
}
2️⃣ Manifest-āĻ Service āĻĄিāĻ্āϞেā§াāϰ āĻāϰা
đ AndroidManifest.xml-āĻ āύিāĻেāϰ āĻŽāϤো āĻāϰে Service āϝোāĻ āĻāϰāϤে āĻšāĻŦে!
<service
android:name=".MyForegroundService"
android:foregroundServiceType="media"
android:permission="android.permission.FOREGROUND_SERVICE" />
3️⃣ Activity āĻĨেāĻে Foreground Service āĻাāϞু āĻāϰা!
val serviceIntent = Intent(this, MyForegroundService::class.java)
startService(serviceIntent)
đ Foreground Service āĻŦāύ্āϧ āĻāϰāϤে:
stopService(serviceIntent)
đĨ Foreground Service āĻāϰ āĻুāϰুāϤ্āĻŦāĻĒূāϰ্āĻŖ āĻĢিāĻাāϰ đĨ
✔️ Always Active – āĻāĻāĻাāϰāĻে āύোāĻিāĻĢিāĻেāĻļāύ āĻĻেāĻিā§ে āĻাāĻ āĻāϰে!
✔️ High Priority Task – āĻ
্āϝাāύ্āĻĄ্āϰā§েāĻĄ āĻāĻাāĻে āĻিāϞ āĻāϰāĻŦে āύা!
✔️ Long-running Operations – āĻĄাāĻāύāϞোāĻĄ, āϞাāĻāĻ āĻ্āϰ্āϝাāĻিং, āĻŽিāĻāĻিāĻ āĻāϤ্āϝাāĻĻিāϰ āĻāύ্āϝ āĻĒাāϰāĻĢেāĻ্āĻ!
✔️ Battery Optimized – āĻŦ্āϝাāĻাāϰি āϞাāĻāĻĢ āĻ িāĻ āϰাāĻে!
❗ Foreground Service āĻāĻŦে āĻŦ্āϝāĻŦāĻšাāϰ āĻāϰা āĻāĻিāϤ?
✅ āϝāĻāύ āĻ
্āϝাāĻĒেāϰ āĻাāĻ āĻāĻāĻাāϰāĻে āĻĻেāĻাāύো āĻĻāϰāĻাāϰ!
✅ āϝāĻāύ āĻ
্āϝাāĻĒ āĻ
āύেāĻāĻ্āώāĻŖ āĻŦ্āϝাāĻāĻ্āϰাāĻāύ্āĻĄে āĻāϞāĻŦে!
✅ āϝāĻāύ āϏাāϰ্āĻিāϏ āĻŦāύ্āϧ āĻšā§ে āĻেāϞে āĻ
্āϝাāĻĒেāϰ āĻাāĻ āύāώ্āĻ āĻšā§ে āϝাāĻŦে!
đĄ āĻŽāύে āϰাāĻāĻŦেāύ:
đ āĻ
্āϝাāύ্āĻĄ্āϰā§েāĻĄ 10 (API 29) āĻĨেāĻে Foreground Service āĻŦ্āϝāĻŦāĻšাāϰেāϰ āĻāύ্āϝ FOREGROUND_SERVICE āĻĒাāϰāĻŽিāĻļāύ āϞাāĻāĻŦে!
đ āϏংāĻ্āώেāĻĒে Foreground Service – āĻāĻ āύāĻāϰে!
đ Foreground Service = āĻŦ্āϝাāĻāĻ্āϰাāĻāύ্āĻĄে āĻāϞা āϏাāϰ্āĻিāϏ + āĻāĻāĻাāϰāĻে āύোāĻিāĻĢিāĻেāĻļāύ!
đ Spotify, YouTube Music, Google Maps – āϏāĻŦ āĻাā§āĻাā§ āĻāĻা āĻŦ্āϝāĻŦāĻšাāϰ āĻšā§!
đ āĻ
্āϝাāύ্āĻĄ্āϰā§েāĻĄ āĻāĻাāĻে āϏ্āĻŦাāĻাāĻŦিāĻ āĻŦ্āϝাāĻāĻ্āϰাāĻāύ্āĻĄ āϏাāϰ্āĻিāϏেāϰ āĻŽāϤো āĻিāϞ āĻāϰāϤে āĻĒাāϰে āύা!
đ Battery Friendly + High Priority Task + User Interaction
đ¯ āĻāĻāύ āĻāĻĒāύি āĻĒুāϰোāĻĒুāϰি Android Foreground Service āĻŽাāϏ্āĻাāϰ! đđĨ
Comments
Post a Comment