如何清除栈回到根系活力,当用户离开应用程序? [英] How to clear stack back to root activity when user leaves application?

查看:97
本文介绍了如何清除栈回到根系活力,当用户离开应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有2活动,LogonAct和MainAct的应用程序。 LogonAct是我要迫使用户去通过每一个他们返回到应用程序的时间登录活动。我给自己定的机器人:clearTaskOnLaunch =真正的在LogonAct

当我第一次开始通过屏幕上的这个序列中的应用程序,我走了,

首页 - > LogonAct - > MainAct - >首页

然后我按照这个顺序,

LogonAct - >返回 - > MainAct

为什么带我回MainAct?如果不是活动的天堂被关闭了,因为LogonAct有机器人:clearTaskOnLaunch =真正的。我预计将带回家里的时候,我从LogonAct打后退按钮。

这是AndroidManifest.xml中的相关片段,

 <活动机器人:LogonActNAME =
             机器人:clearTaskOnLaunch =真正的>
       <意向滤光器>
           <作用机器人:名称=android.intent.action.MAIN/>
           <类机器人:名称=android.intent.category.LAUNCHER/>
       &所述; /意图滤光器>
   < /活性GT;

   <活动机器人:名称=。MainAct>
       <元数据的android:NAME =android.app.default_searchable
                  机器人:值=。SearchResult所/>
   < /活性GT;
 

我使用的是1.5。

任何帮助AP preciated。

解决方案

该文档的安卓clearTaskOnLaunch 提到,这个属性应用于每当[活动]为重从主屏幕上。

推出

不过,你的情况,你是pressing的<大骨节病>首页按钮返回主屏幕,而不是pressing的<大骨节病>返回按钮。这意味着你的应用程序实际上不是的重新启动的,因为 MainAct 并没有完成。这仅发生在你preSS <大骨节病>返回(或者安卓杀死任务,节约资源等)。

因为你只需要在应用程序中的两项活动,您可以设置<一个href="http://developer.android.com/guide/topics/manifest/activity-element.html#nohist"><$c$c>android:noHistory属性对 MainAct ,从而确保用户永远不能恢复到它,必须通过 LogonAct

顺便说一句,似乎有点恼人,迫使用户重新登录每次他们从应用程序导航离开时间(例如,当他们收到电话)。
你可以保持与超时会话令牌在你的应用程序的永久存储,或保持网络连接打开使用服务,如果这是如何您的应用程序的工作原理&mdash;但当然,这是给你和你的要求。 :)

I have an application with 2 activities, LogonAct and MainAct. LogonAct is a logon activity which I want to force the user to go through each time they return to the application. I've set android:clearTaskOnLaunch="true" on LogonAct.

When I first start the app I go through this sequence of screens,

Home -> LogonAct -> MainAct -> Home

I then follow this sequence,

LogonAct -> Back -> MainAct

Why is it bringing me back to MainAct? Shouldn't that activity haven been closed since LogonAct has android:clearTaskOnLaunch="true". I expected to be brought back to Home when I hit the Back button from LogonAct.

Relevant snippets from AndroidManifest.xml,

   <activity android:name=".LogonAct"
             android:clearTaskOnLaunch="true">
       <intent-filter>
           <action android:name="android.intent.action.MAIN"/>
           <category android:name="android.intent.category.LAUNCHER"/>
       </intent-filter>
   </activity>

   <activity android:name=".MainAct">
       <meta-data android:name="android.app.default_searchable"
                  android:value=".SearchResults" />
   </activity>

I'm using 1.5.

Any help appreciated.

解决方案

The docs for android:clearTaskOnLaunch mention that this attribute applies "whenever [the Activity] is re-launched from the home screen".

However, in your case you're pressing the Home button to return to the Home screen, rather than pressing the Back button. This means your application isn't actually relaunched because the MainAct was not "finished". That only happens when you press Back (or if Android kills the task to save resources etc.).

As you only have two activities in your application, you could set the android:noHistory attribute on MainAct, thus ensuring that users can never return to it and must pass through the LogonAct.

As an aside, it seems a bit annoying to force users to re-login every time they navigate away from the app (for example when they receive a phone call).
You could retain a session token with timeout in your app's persistent storage, or hold a network connection open using a service if that's how your app works — but of course that's up to you and your requirements. :)

这篇关于如何清除栈回到根系活力,当用户离开应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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