resuming an activity from a notification

前端 未结 7 2169
刺人心
刺人心 2020-11-30 12:24

I have a notification in the status bar for my app:

    Notification notification = new Notification(R.drawable.icon, null, System.currentTimeMillis());

            


        
相关标签:
7条回答
  • 2020-11-30 12:57

    You can simulate a launch intent (as if the user clicked on your app icon to launch it):

    val launchIntent = context.packageManager.getLaunchIntentForPackage(context.packageName)
    
    val contentIntent = PendingIntent.getActivity(context, 0, launchIntent, 0)
    

    This way, you do not have to mark your app as "singleTask" or "singleInstance" in Manifest (which would create other issues). Thus this should be the proper solution.

    Note, however, the above solution may not work directly for you, due to an alleged android bug. Discussions about the android bug and a workaround can be found in this question.

    0 讨论(0)
提交回复
热议问题