如何回到之前的2屏Android?

发布于 2025-01-14 23:40:13 字数 397 浏览 0 评论 0原文

场景是这样的:我有 3 页;第一页A为主页面,使用splash,第二页为B页,第三页为C页。我想从 C 导航到 A,但我不想看到飞溅。我不想看到飞溅,但当我打开页面时总会出现飞溅。我不想删除飞溅。

我尝试一些代码,例如:

1-Intent goScreen = new Intent(C.this or this@C, A.class); goScreen.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(gotoScreenVar);

2-val Intent = Intent(this@A, C::class.java) startActivity(意图) ...

This is the scenario: I've got 3 pages; the first page A is the main page and uses splash, the second page is the B page, the third page is the C page. I want to navigate from C to A but I do not want to see the splash. I don't want to see splash but when I open page A splash always comes. I don't want to delete splash.

I try some code e.g. :

1-Intent goScreen = new Intent(C.this or this@C, A.class);
goScreen.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(gotoScreenVar);

2-val intent = Intent(this@A, C::class.java)
startActivity(intent)
...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

抚笙 2025-01-21 23:40:13

从活动 C 导航到活动 A 时,您可以将一些数据传递给意图。
与 Activity A一样

intent.putBoolean("shouldHideSplash", true);

,您可以检查 Intent 是否有 shouldHideSplash,您可以跳过启动画面并可以做任何您想做的事情。

While navigating from Activity C to Activity A, you can pass some data to the intent.
Like

intent.putBoolean("shouldHideSplash", true);

and on Activity A, you can check if intent has shouldHideSplash, you can skip the splash and can do whatever you want.

烛影斜 2025-01-21 23:40:13

创建这个扩展属性:

val Activity.isLaunchedFromHomeScreen: Boolean
    get() = intent?.let {
        it.action == Intent.ACTION_MAIN &&
                it.categories.orEmpty().contains(Intent.CATEGORY_LAUNCHER)
    } ?: false

然后在Activity A中,您可以检查这个布尔值来决定是否显示启动画面。

但我警告您不要以这种方式创建启动屏幕。现在 Android 12 已内置启动画面,您的应用将在 Android 12 及更高版本上显示两个启动画面。您可能需要使用启动画面库来创建一个在所有版本的 Android 上一致地工作。或者创建另一个属性来决定仅在低于 Android 11 的版本上显示您的实现:

val shouldShowSplashScreen: Boolean 
    get() = isLaunchedFromHomeScreen && Build.VERSION.SDK_INT < Build.VERSION_CODES.R

Create this extension property:

val Activity.isLaunchedFromHomeScreen: Boolean
    get() = intent?.let {
        it.action == Intent.ACTION_MAIN &&
                it.categories.orEmpty().contains(Intent.CATEGORY_LAUNCHER)
    } ?: false

Then in Activity A, you can check this Boolean to decide whether to show the splash.

But I caution you about creating a splash screen this way. Now that Android 12 has built-in splash screens, your app is going to show two splash screens on Android 12 and higher. You might want to use the splash screen library to create one that works consistently across all versions of Android. Or create another property to decide to show your implementation only on versions lower than Android 11:

val shouldShowSplashScreen: Boolean 
    get() = isLaunchedFromHomeScreen && Build.VERSION.SDK_INT < Build.VERSION_CODES.R
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文