如何总是从Android上启动活动的开始呢? [英] How to always start from a startup activity on Android?

查看:104
本文介绍了如何总是从Android上启动活动的开始呢?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有三种不同的情况:

1)用户启动一个应用程序,导航在里面,pressed家里点击应用程序图标再次再次启动我们的应用程序。

1) A user launches an app, navigates in it, pressed home and click on the app icon again to launch our app again.

2)用户启动一个应用程序,导航在里面,presses家,选择最近,点击应用程序来再次启动我们的应用程序。

2) A user launches an app, navigates in it, presses home, chooses recent and click on the app to launch our app again.

3)用户启动一个应用程序,导航它,单击应用程序(TextView中的链接),它调用其他应用程序(如例如电子邮件)和用户点击后退按钮,这使我们回到我们的应用程序的东西。

3) A user launches an app, navigates in it, click something in the app (TextView with a link), which calls another app (as example Email) and user clicks back button, which bring us back to our app.

我知道的标志clearTaskOnLaunch标志,它解决的情况下,#1。

I know about flag "clearTaskOnLaunch" flag, it solves case #1.

我知道有关标志excludeFromRecents,它解决的情况下,#2(可能不是最用户友好的解决方案,但它的工作原理)。

I know about about flag "excludeFromRecents", it solves case #2 (may be not the most user friendly solution, but it works).

什么情况#3?我有一个解决办法现在。不过,我将不得不把它放在可导致其他应用程序的所有活动。我想知道,是否有更好的方法来解决这个问题(没有处理它所有此类活动)。

What about case #3? I have a workaround right now. However, I will have to put it on all activities which can be lead to another app. I wonder, whether there is better way to solve it (without handling it in all such activities).

推荐答案

这应该在应用层的程序。

This should be handled on the Application level.

有关API级别14,你可以在你的应用程序类注册一个ActivityLifeCycleCallback

For API level 14, you can register an ActivityLifeCycleCallback in your Application class

public void registerActivityLifecycleCallbacks (Application.ActivityLifecycleCallbacks callback)

您可以使用它,要知道在一个应用层,它的活动被破坏,暂停,恢复等等等等无论何时,活动被暂停,而不会创​​造了一个新的活动/恢复,您应该清除活动堆栈,并重新启动您的startActivity

You can use it, to know on an Application level, which activities are destroyed, paused, resumed etc etc. Whenever, an activity is paused, without a new activity being created/resumed, you should clear the Activity stack, and re-launch your startActivity

如果你的目标SDK版本< 14,你要实现你自己的方法,要知道创建哪些活动/恢复,停了下来,并做某项活动被暂停一样,如果没有新的活动正在创建/恢复

If you target SDK versions < 14, you should implement your own method, to know which activities are created/resumed and paused, and do the same whenever an activity is paused, without a new activity being created/resumed

这篇关于如何总是从Android上启动活动的开始呢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆