如何清除栈回到根系活力,当用户离开应用程序?根系、应用程序、活力、用户

由网友(做个王)分享简介:我有2活动,LogonAct和MainAct的应用程序。 LogonAct是我要迫使用户去通过每一个他们返回到应用程序的时间登录活动。我给自己定的机器人:clearTaskOnLaunch =真正的在LogonAct 当我第一次开始通过屏幕上的这个序列中的应用程序,我走了,首页 - > LogonAct - &...

我有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;
 
操作系统 哈工大视频教程 第11讲到第15讲

我使用的是1.5。

任何帮助AP preciated。

解决方案

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

推出

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

因为你只需要在应用程序中的两项活动,您可以设置android:noHistory属性对 MainAct ,从而确保用户永远不能恢复到它,必须通过 LogonAct

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

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. :)

阅读全文

相关推荐

最新文章