gpt4 book ai didi

Android:确定应用程序何时完成

转载 作者:行者123 更新时间:2023-11-30 04:52:59 25 4
gpt4 key购买 nike

我昨天发布了一个关于确定应用程序何时因屏幕方向更改而完成或销毁的问题。多亏了我收到的答案,我才能够解决屏幕方向更改的问题。但是,我仍然遇到了障碍。我正在处理的这个应用程序使用 HttpClient 登录到网站。只要应用程序保留在内存中,HttpClient 就会保留登录时的 cookie。但是,一旦它被终止,它就需要重新登录。我的问题:如何确定应用程序何时从内存中被杀死,以便我可以将 bool 值设置为 false 告诉应用程序它已从内存中删除,以便下次启动时它会读取它并确定是否必须再次登录?或者是否可以序列化 HttpClient 并将其放入 savedInstanceState 包中?可以从客户端提取 cookie 并将它们放入 savedInstanceState 包中吗?也许我在这里完全缺少什么?非常感谢任何帮助或指向正确方向的一点,因为这让我很困惑。谢谢!

最佳答案

How can I determine when the app is being killed from memory so I can set a boolean to false telling the app it has been removed from memory so the next time it starts it will read this and determine is must log in again?

恕我直言,这是错误的问题。

正确的问题是:“我怎么知道 cookie 已经消失了?”

更接近于真正的业务问题(“我怎么知道我是否必须再次登录?”),因此与假设某些系统相比,它将涵盖更多潜在的边缘和角落情况事件是 cookie 消失的唯一来源。

此外,它更容易:您的 HttpClient 对象可以让您访问 CookieStore,并且您可以遍历那些 cookie 以查看您的 cookie 是否在其中。不可否认,如果他们在该类上有一个更直接的方法来进行此类查找,那就太好了。

因此,在访问 Web 应用程序之前,请检查 cookie 是否存在,并在需要时弹出登录对话框/Activity/任何内容。

Or is it possible to serialize an HttpClient and put that in the savedInstanceState bundle?

没有。

May extract the cookies from the client and put those in the savedInstanceState bundle?

是的,但是你会花很多时间将它们放回 CookieStore,IIRC。

关于Android:确定应用程序何时完成,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2485865/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com