Android back-stack not being created from Notification PendingIntent

有些话、适合烂在心里 提交于 2019-12-04 06:26:47

It turns out that I needed to add a flag to the intent and use the application context. I didn't need the whole creation of the backstack in java inside the target class, just in the manifest.xml. So I built this little method to build the pending intents properly and consistently for me.

public static PendingIntent addBackStack(final Context context, final Intent intent) {
   TaskStackBuilder stackBuilder = TaskStackBuilder.create (context.getApplicationContext ());
   stackBuilder.addNextIntentWithParentStack (intent);
   intent.addFlags (Intent.FLAG_ACTIVITY_NEW_TASK);
   return stackBuilder.getPendingIntent (0,PendingIntent.FLAG_UPDATE_CURRENT);
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!