Tengo el siguiente codigo para enviar una notificacion luego de varios millisegundos desde un service todo funciona perfecto aun cuando salgo de la aplicacion pero quisiera que los millisegundo sigan contandose aun cuando destruyo la app. Alguna idea de que me falta implementar para lograr esto?
class MyServicio : Service() {
companion object{
val ID_CHANNEL:String = "com.example.channelnotification";
val NAME_CHANNEL:String = "Android_Channel";
private val Notification_ID = 0;
}
override fun onCreate() {
super.onCreate()
CreateChannelNotification()
}
private fun CreateChannelNotification() {
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O){
val importance = NotificationManager.IMPORTANCE_HIGH
val channel = NotificationChannel(ID_CHANNEL, NAME_CHANNEL,importance).apply{
description = "Esta es la notifiacion"
}
val notificationManager:NotificationManager = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
notificationManager.createNotificationChannel(channel)
}
}
private fun ShowNotification(){
val builder = NotificationCompat.Builder(applicationContext, ID_CHANNEL)
.setSmallIcon(R.drawable.noti)
.setContentText("Notificado")
.setContentTitle("Recivido")
.setPriority(NotificationCompat.PRIORITY_DEFAULT)
with(NotificationManagerCompat.from(this)) {
notify(Notification_ID, builder.build())
}
}
val myDate = "2020/11/29 18:10:45"
val sdf = SimpleDateFormat("yyyy/MM/dd HH:mm:ss")
val date: Date = sdf.parse(myDate)
val millis = date.time
override fun onBind(intent: Intent?): IBinder? {
return null;
}
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
Handler(Looper.getMainLooper()).postAtTime({
Log.e(TAG,"Service is runing");
ShowNotification()
}, SystemClock.uptimeMillis() + 3000)
return START_STICKY;
}
}