0

I want to send two string values ​​and an object (list).

When sending only 'uid' and 'job' data, the data is received well.(in broadcastreceiver)

However, the moment an object (list) is added, all data is received as null. (This is a log I tried.)

When I took a log in the CharacInfo class, I checked that the bundle contains a value.

But why am I getting null in broadcastreceiver ?

The type of object I want to pass is as follows.

THIS IS CHARACINFO CLASS LOG... *bundle:Bundle[{job=용병, uid=19, list=[CharacInfo(uid=1, category=0, img=2131165293, job=주술사, birth=0103), CharacInfo(uid=2, category=0, img=2131144643, job=마술사, birth=0105)] ....

This is the CharacInfo class.

@Entity
@Parcelize
data class CharacInfo(
    @PrimaryKey val uid: Long,
    @ColumnInfo var category: Int,
    @ColumnInfo var img: Int,
    @ColumnInfo var job: String,
    @ColumnInfo var birth: String
) : Parcelable {


    @SuppressLint("SimpleDateFormat")
    fun executionAlarm(context: Context, uid: Int, job: String, list: List<CharacInfo>) {

        val alarmManager = context.getSystemService(Context.ALARM_SERVICE) as AlarmManager
        val intent = Intent(context,AlarmBroadcast::class.java)

        val arrayItem: ArrayList<CharacInfo> = ArrayList(list)

        Log.d("jjs","executionAlarm: $uid, array:${arrayItem}")
//        intent.putExtra(UID_KEY,uid.toString())
//        intent.putExtra(JOB_KEY,job)
//        intent.putParcelableArrayListExtra(LIST_KEY, arrayItem)

        val bundle = Bundle()
        bundle.putString(UID_KEY,uid.toString())
        bundle.putString(JOB_KEY,job)
        bundle.putParcelableArrayList(LIST_KEY,arrayItem)
        intent.putExtras(bundle)

        Log.d("list_key","bundle:${bundle}")


        Log.d("list_key","CharacInfo uid : $uid")
        Log.d("list_key","CharacInfo job : $job")


        Log.d("gggg","CHARACINFO===============")

        val pendingIntent = PendingIntent.getBroadcast(context, uid,intent,PendingIntent.FLAG_MUTABLE)
        //0503

        val month = birth.substring(0 until 2).toInt()
        val day = birth.substring(2 until 4).toInt()

        val checkNumBol = month.toString().isDigitsOnly()

        val calendar = Calendar.getInstance()
        calendar.timeInMillis = System.currentTimeMillis()
        calendar.set(Calendar.YEAR,calendar[Calendar.YEAR])
        if(checkNumBol) {
            calendar.set(Calendar.MONTH,month-1)
        }
        calendar.set(Calendar.DAY_OF_MONTH,day)
        calendar.set(Calendar.HOUR_OF_DAY,13)
        calendar.set(Calendar.MINUTE,0)
        calendar.set(Calendar.SECOND,0)
        calendar.set(Calendar.MILLISECOND,0)

        if(calendar.timeInMillis <= System.currentTimeMillis()) {
            calendar.set(Calendar.YEAR,calendar.get(Calendar.YEAR) + 1)
        }

    alarmManager.setExact(AlarmManager.RTC_WAKEUP,calendar.timeInMillis,pendingIntent)
    }

This is BroadcastReceiver class

class AlarmBroadcast : BroadcastReceiver() {

    override fun onReceive(context: Context?, intent: Intent) {


        val uid = intent.getStringExtra(UID_KEY)
        val job = intent.getStringExtra(JOB_KEY)
        val lists : ArrayList<CharacInfo> = intent.getParcelableArrayListExtra(LIST_KEY)!!


        Log.d("list_key","broadcastreceiver uid : ${uid}")
        Log.d("list_key","broadcastreceiver job : ${job}")
        Log.d("list_key","broadcastreceiver list : ${lists}")

        val serviceIntent = Intent(context, EmptyService::class.java)


//        Log.d("gggg", "serviceIntent charac:${charac}")

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
//            context?.startForegroundService(serviceIntent)
        } else {
//            context?.startService(serviceIntent)
        }

    }
}
luullu
  • 1
  • 2

0 Answers0