android - 如果应用程序已经打开或在后台,待定 Intent 不会启动 Activity

标签 android android-intent android-widget android-pendingintent

在我的应用程序中,我有一个小部件。如果用户单击小部件,我将使用下面的代码使用挂起的 Intent 打开 SplashScreen。

PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
    views.setOnClickPendingIntent(R.id.widget_main_layout, pendingIntent);

此代码工作正常,应用程序未打开并启动我的启动画面。

但是,如果应用程序已经打开并在后台,并且如果我单击小部件,那么我的 SplashScreen 不会打开,而是只有应用程序会出现在前台。

谁能让我知道我的代码有什么问题?

最佳答案

使用此代码
intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP);

关于android - 如果应用程序已经打开或在后台,待定 Intent 不会启动 Activity,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54231339/

相关文章:

java - 发送 ISO8583 请求时出现 NullPointerException

java - 在 Java 和 Android 客户端上解析 JSON 对象的最佳实践

java - Android Spinner 抛出 Java.lang.nullpointerexception - Android Beginner

android - 如何默认在 ActionOpenDocument Intent 中显示 "internal storage"选项

android获取gridview中被点击项的位置

android - 在 onPostCreate 中调用 onCreateOptionsMenu

javascript - 为显示的 webview 添加底部边框

android - 如何从代码开始和停止电话

java - webview中的网页是空白的

android - android :layout_weight mean? 是什么意思