在我的应用程序中,我有一个小部件。如果用户单击小部件,我将使用下面的代码使用挂起的 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/