启动应用程序与“最近的应用程序"之间有什么区别?并点击应用程序图标 [英] What is the difference between launch app from "recent apps" and tapping app icon

查看:39
本文介绍了启动应用程序与“最近的应用程序"之间有什么区别?并点击应用程序图标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在处理大型项目,所以有一些逻辑可以保存应用程序状态,然后在它来自后台时打开正确的活动(片段).但无论如何,我发现如果用户浏览我的应用程序然后将其最小化 - 在以下情况下,android 会以不同的方式从后台打开它:

I'm working on large project, so there is some logic for saving application state, and then opening correct activity(fragment) when it comes from background. But anyway, I've found that if user navigates through my app and then minimize it - android opens it from background in different ways in following cases:

  1. 用户点击应用图标(行为:用户看到家庭活动,无论他在哪里,应用何时最小化)
  2. 用户从 android最近的应用程序"中选择应用程序(行为:当应用程序最小化时,用户可以准确地看到他看到的内容)
  1. User taps on app icon (behavior: user see home activity, doesn't matter where he was, when application was minimized)
  2. User select app from android "recent apps" (behavior: user see exactly what he saw, when the application was minimized)

那么,这两种方式从后台启动应用程序有什么区别?我一直认为,这是相同的机制,但显然,我错了.

So, what is the difference between launching application from background by this two ways? I always thought, that it is the same mechanism, but, obviously, I was wrong.

感谢您的回答

推荐答案

您应该注意以下文档 活动任务.简而言之:如果用户从最近启动应用程序,您将在 onStart 之前收到 onRestart (没有 onCreate 这意味着您的应用程序只是暂停").您可以使用 onSaveInstanceState() 保存屏幕状态.但通常从图标和最近开始 - 不同的应用程序行为,您应该为这种方式提供适当的代码.

更新如下所述,意外行为的根本原因是额外的午餐模式属性.

You should pay atention on the folowing docs Activity and Tasks. In short words: if user start app from recents you will receive onRestart before onStart (without onCreate it means that your app was just "suspended"). You able to save screen state using onSaveInstanceState(). But in general starting from icon and from recents - different application behaviors and you should provide proper code for this ways.

UPD As described below root cause of unexpected behaviour was additional lunchmode attribute.

这篇关于启动应用程序与“最近的应用程序"之间有什么区别?并点击应用程序图标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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