Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to save&load a snapshot of an Android app state?

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?

like image 784
android developer Avatar asked Nov 02 '22 23:11

android developer


1 Answers

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.

like image 68
frapen Avatar answered Nov 09 '22 10:11

frapen