7

Before reading this, note that I'm not talking about capturing the screen.

Motivation

Many times, in order to test apps, we need to go over many activities (including a loading/splash screen) till we reach the one we've just updated in order to test it out.

I want to reduce this time , by capturing the exact state of the app (memory,preferences,activities stack,...) in order to go there again.

Another example : The QA team could show me in which case a bug occurs, without having to show me the whole process till they got there (since it might not be reproducible) and then I could run the app, and know exactly where the exception was thrown and go there directly via the DDMS's logs .

Another example: We work on a game, and the QA team have tested the game for hours and reached a certain stage, and would like to save the current state of the app in order to test it from this point and make multiple tests on it, instead of running the app from the beginning each time , wait for it to load and also finish all of the stages till they reach this stage.

I think there are other scenarios where such a thing could be useful.

The problem

Such a thing is probably possible in the VM world (for example virualBox) , and it's probably possible for android emulators (at least according to this post , but they also say it's "finicky" , not sure what that means in this context) , but not for devices.

The above example, though they might work, they work for the entire OS and not for a specific app, so even if I choose to use them, it takes a long time to use (plus I need to use an emulator which is usually much slower than any device) .

I'm pretty sure that the current API doesn't support such a thing (and it's probably a good thing, for security reasons).

The question

Is it possible to capture&load entire app state by using ROOT ? Maybe by being a system app too?

Maybe there is already an app for this task?

Community
  • 1
  • 1
android developer
  • 114,585
  • 152
  • 739
  • 1,270

1 Answers1

2

Since it's very usual that an application saves its whole state in SharedPreferences and persistence in DB, in most apps you can backup and restore data and state using adb backup and adb restore, respectively:

Backup:

adb backup -f app.ab com.company.app

Restore:

adb restore app.ab

PS: This feature was introduced in ICS, and it's not required to be root.

More information in this tutorial.

frapen
  • 147
  • 2
  • 15
  • In order to get this stuff working, the `AndroidManifest` property [`allowBackup`](http://developer.android.com/reference/android/app/backup/BackupManager.html#attr_android:allowBackup) must be set to true. – frapen Jun 02 '15 at 21:51
  • How could it work in case "allowBackup" isn't enabled? Also, as I remember, this method requires a password to be set, no? – android developer Jun 02 '15 at 22:05
  • Android ask for your password used to unlock the device, due to security concerns. Also, this password is used to encrypt the `ab` file. On the other hand, no password is required for restore data. I'm afraid this feature won't work if `allowBackup` is `false`. – frapen Jun 02 '15 at 22:12
  • Then how does third party apps do this? Also, BTW, the question here is about the entire state of the app, including RAM and where each thread has stopped. But saving&loading data is also interesting. – android developer Jun 02 '15 at 22:23
  • 1
    Sorry, I have not found any third party app to do this. Could you name someone? I suppose you can bypass the `allowBackup` limitation if your are **root**, but I'm not sure. Lastly, you are looking for a method to implement [**Application checkpointing**](http://en.wikipedia.org/wiki/Application_checkpointing) under Android. Since Android is a light version of Linux, it is _in theory_ possible. Also, you can take a look to [this presentation](http://elinux.org/images/1/1c/Implement_Checkpointing_for_Android.pdf) that delves into these mechanisms. – frapen Jun 02 '15 at 22:47
  • 2
    backup apps like "EaseBackup" and "Titanium Backup ★ root" can backup any app, including their data. about the original question, thank you. I will check the links when I get the chance. – android developer Jun 03 '15 at 05:21
  • Is there any way to save android phone state as a snapshot and use it later. Just like hibernate in laptops. We can achieve it on emulators, not sure how we can achieve it on real device – Manish Patiyal May 27 '22 at 12:46