【发布时间】:2019-06-11 09:10:37
【问题描述】:
在我的应用程序中,我有一个小部件。如果用户点击小部件,我将使用下面的代码使用挂起的意图打开 SplashScreen。
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
views.setOnClickPendingIntent(R.id.widget_main_layout, pendingIntent);
此代码工作正常,应用程序未打开并启动我的启动画面。
但是,如果应用程序已经打开并处于后台,并且如果我单击小部件,则我的 SplashScreen 不会打开,而是只有应用程序会进入前台。
谁能告诉我我的代码有什么问题?
【问题讨论】:
-
你如何构建
intent?你试过intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT)吗? -
哦,我想你每次点击小部件时都想从 splash 中打开 APP。我对吗?
-
是的。我想每次用户点击小部件时打开应用程序
-
因为你的标志是
PendingIntent.FLAG_UPDATE_CURRENT,你应该把它改成FLAG_CANCEL_CURRENT -
请将用于生成
intent的代码添加到您的帖子中。
标签: android android-intent android-widget android-pendingintent