简体   繁体   English

Android SingleTask onResume保持状态

[英]Android SingleTask onResume persist state

I have this Android application where I am using branch.io for deeplinking and it works best when the the app has only one instance so I am using android:launchMode="singleTask" 我有一个Android应用程序,我在其中使用branch.io进行深层链接,当该应用程序只有一个实例时,它工作得最好,所以我使用的是android:launchMode =“ singleTask”

My problem is when I background the app, it always clear all my memory and it is annoying because I don't want all the memory to be cleared. 我的问题是当我后台运行该应用程序时,它总是清除我的所有内存,这很烦人,因为我不想清除所有内存。

Is there a way for us to have singleTask and also not have all the app's memory cleared when we go from background to foreground? 当我们从后台运行到前台时,有没有办法让我们拥有singleTask并且没有清除所有应用程序的内存?

The issue you're running into is that having android:launchMode="singleTask" means that specific deep-linked activity is the start of the activity stack , and is a single instance, so when you get deep-linked through AppLinks, this gets invoked first. 您遇到的问题是,拥有android:launchMode =“ singleTask”意味着特定的深度链接活动是活动堆栈开始 ,并且是单个实例,因此当您通过AppLinks进行深度链接时,首先调用。

In case you want to use singleTask, have it be on an Activity that acts as a "SplashActivity", or a BaseActivity that all deep-linked activities inherit from, that can handle being a single activity, and can drive users to the actual deep-linked Activity you need to reach. 如果要使用singleTask,请将其放在充当“ SplashActivity”的Activity或所有深层链接活动都继承自的BaseActivity上,它可以处理为单个活动,并且可以将用户带入实际的深层链接的活动,您需要达到。

Then, whenever the app is taken to the background, the BaseActivity will be notified of onStop and you can save your work there. 然后,无论何时将应用程序带到后台,都会将onStop通知给BaseActivity,您可以在其中保存您的工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM