Persisting app's sensitive data in-memory after app is killed by Android system
<p>I'm newer to Android development and have a problem I haven't really been able to figure out after a good amount of research.</p>

<p>I have <a href="https://turtl.it" rel="nofollow">an open-source app</a> (Cordova, but slowly trying to build away from it) that handles end-to-end encrypted user data. The data is encrypted via the user's key, which is generated from their password. This all works great.</p>

<p>My problem (and my users' problem) is that the app gets killed when it's in the background and my users have to log back in. Long passwords are preferred obviously because of the private nature of the app, but typing your password each time the app opens is a real pain.</p>

<p>So I have a few questions about services (and please let me know if there's a better way):</p>

<p>Can I have a service store the user's authentication information such that:</p>

<ul>
<li><strong>the auth info is never saved to disk (memory only)</strong></li>
<li>the service will live on even if the main app is killed</li>
<li>only my app can talk to the service</li>
</ul>

<p>I've been checking out foreground services and it seems like it may be what I want, <em>however</em> I don't want the foreground service to keep my app from being killed...in other words if the system doesn't want my app to run I don't want to hold resources hostage with a service. I just want to be able to pull the auth info out when the app starts again so the user doesn't have to log in again.</p>

<p>Any help is greatly appreciated!!</p>