Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

175
Vistas
What does requestCode represent?

I thought requestCode was some kind of indentifier for which Intent was just called for or something like that, please correct me if i'm wrong. But if this is the case, why is that if the requestCode for my pendingintent is 2, it acts differently when I have pass the requestcode as 0. I don't have another pendingintent in which is passed 2 as the requestcode.

Say I start my app and then I get a notification, when I click this notification ...

requestCode = 2 ...a new activity is created and brought to the foreground, when I press the back button I go back to the activity I was on in the same state before backing out of the app

requestCode = 0 ...I go straight back to the activity I was on in the same state before backing out of the app. No new activity is created

This isn't really a big issue, I could just pass 0 and the app will work how I want it to but I just wanna know why this happens.

In MainActivity.kt

    private fun startAlarm (cal : Calendar){
        val alarmManager :AlarmManager = getSystemService(Context.ALARM_SERVICE) as AlarmManager
        val intent = Intent (this, AlertReceiver().javaClass)
        val pendingIntent : PendingIntent = PendingIntent.getBroadcast(this, 1, intent, 0)
        alarmManager.setExact(AlarmManager.RTC_WAKEUP, cal.timeInMillis, pendingIntent)
    }
}

AlertReceiver.kt

class AlertReceiver(): BroadcastReceiver() {

    @RequiresApi(Build.VERSION_CODES.O)
    override fun onReceive(context: Context?, intent: Intent?) {
        val notificationObj : Notification = Notification(context)
        val notif : NotificationCompat.Builder = notificationObj.createNotification()

        notificationObj.getManager().notify(1, notif.build())
    }
}

In Notification.kt

fun createNotification(): NotificationCompat.Builder{
        val main: Intent = Intent (this, MainActivity().javaClass).apply {
            flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK
        }
        //-------------------talking about this line--------------------------------
        val pendingMain: PendingIntent = PendingIntent.getActivity(this, 2, main, 0)
        val notif : NotificationCompat.Builder = NotificationCompat.Builder(applicationContext, channelID)
            .setSmallIcon(R.drawable.ic_android_black_24dp)
            .setContentTitle("test:")
            .setContentText("testing")
            .setPriority(NotificationCompat.PRIORITY_DEFAULT)
            .setContentIntent(pendingMain)
            .setAutoCancel((true))

        return notif
    }
over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

When you are passing data from multiple Fragments to an Activity using onActivityResult(), that Activity identifies the child Fragment via request code

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda