Notification bring app to front without change activity

后端 未结 3 1304
梦毁少年i
梦毁少年i 2021-02-12 16:44

I want to create notification that when it clicked will bring my app to front but without changing (reload or navigate out) the last activity that was shown.

I tried: <

相关标签:
3条回答
  • 2021-02-12 17:05

    You don't ever set Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT. That flag is set by Android when it brings the activity to the front. You setting it has no effect.

    There's a few ways to do what you want. Check out this answer

    0 讨论(0)
  • 2021-02-12 17:13

    Working solution for me was :

        //Resume or restart the app (same as the launcher click)
    val resultIntent = Intent(context, MyLauncherActivity::class.java)
    resultIntent.addCategory(Intent.CATEGORY_LAUNCHER)
    resultIntent.setAction(Intent.ACTION_MAIN)
    resultIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
    val pendingIntent = PendingIntent.getActivity(context, 0, resultIntent, PendingIntent.FLAG_UPDATE_CURRENT)
    builder.setContentIntent(pendingIntent)  //builder is the notificationBuilder
    
    0 讨论(0)
  • 2021-02-12 17:21

    Add this "Intent.FLAG_ACTIVITY_PREVIOUS_IS_TOP" instead of "Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT"

    Explained here

    Hope this helps.

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