ActivityManager.getRunningTasks is deprecated android

前端 未结 5 1278
情书的邮戳
情书的邮戳 2020-12-01 05:51

I am working on push notification in android where i am using a below method to show notification, but the problem is that now ActivityManager.getRunningTasks(1); is being

5条回答
  •  爱一瞬间的悲伤
    2020-12-01 06:29

       val cn: ComponentName
        val am = applicationContext.getSystemService(Context.ACTIVITY_SERVICE) as ActivityManager
        cn = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            am.appTasks[0].taskInfo.topActivity
        } else {
            am.getRunningTasks(1)[0].topActivity
        }
    

    This is work for me

提交回复
热议问题