36

An update to the Android development tools was just released enabling you to save-to and restore-from an emulator snapshot. Does anyone know how to use this feature? This would greatly reduce the emulator's load time! But I can't find a way to tell the emulator to do so. Thanks.

Gaurav
  • 391
  • 1
  • 3
  • 7

6 Answers6

29

Honeycomb introduced this feature, and it's pretty cool! It's like the hibernate feature on a laptop. You're saving the state of the emulator into a big file, and restoring its state from the file later.

There are a couple of ways to get it. The first way is to set your desired options in the Launch Options dialog when Starting the emulator from the Android SDK and AVD Manager (see image below). The Wipe user data option is still there from before, and that will create a new system from scratch. The new snapshot options are to Launch from snapshot (if one has been saved previously), or to Save to snapshot when the emulator shuts down. Obviously you have to save a snapshot before you can launch from one. The snapshot file can get rather large, and this adds to how long it takes for the emulator to exit when you close it. But it's worth it. Launching from a snapshot is very quick, compared to going through the entire boot-up sequence of Android. One of the tricks you could do is Save to snapshot once, then Launch from snapshot but don't Save to snapshot after that first time. Your startups will be fast and your exits will be fast. You'll be starting from the same snapshot state every time though, no matter what you do in each emulator session.

enter image description here

The other way to use snapshots is from the command line of emulator. The documentation currently doesn't mention these options, but by invoking the help option on emulator, we find these:

-snapstorage <file>            file that contains all state snapshots (default <datadir>/snapshots.img)
-no-snapstorage                do not mount a snapshot storage file (this disables all snapshot functionality)
-snapshot <name>               name of snapshot within storage file for auto-start and auto-save (default 'default-boot')
-no-snapshot                   perform a full boot and do not do not auto-save, but qemu vmload and vmsave operate on snapstorage
-no-snapshot-save              do not auto-save to snapshot on exit: abandon changed state
-no-snapshot-load              do not auto-start from snapshot: perform a full boot
-snapshot-list                 show a list of available snapshots
-no-snapshot-update-time       do not do try to correct snapshot time on restore

I haven't tried snapshots from the command line since the Launch Options dialog is easier. EDIT: One more thing, the snapshot file gets stored in the same place as your AVD files.

Dave MacLean
  • 5,163
  • 2
  • 22
  • 31
  • 4
    a small addition: snapshot options will be grayed-out unless when creating the AVD you chose "Enable snapshots". – rony l Feb 12 '11 at 13:19
  • 3
    That's true. But you can Edit an existing AVD to enable snapshots. So there's no need to go back and recreate all your existing ones. – Dave MacLean Feb 12 '11 at 16:58
  • 2
    +1 for including the *command line* version, and storage path – n611x007 Oct 24 '13 at 10:30
21

Apparently you can also do it via the console interface:

$ telnet localhost 5554
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
Android Console: type 'help' for a list of commands
OK
avd snapshot save foo
Jan Berkel
  • 3,373
  • 1
  • 30
  • 23
  • `emulator: Listening for console connections on port: 5554` but got `Connecting To localhost...Could not open connection to the host, on port 5554: Connect failed` – FindOut_Quran Dec 10 '16 at 05:01
  • 1
    For people who like me find this in 2017, this feature seems to be absent in tools v25. To use it one needs to downgrade to v24. – Ishamael Jan 31 '17 at 17:01
  • 1
    From what I can see (April 2017), this seems to be missing in Tools v25 (the error says that the option is not supported), however in Tools v26 snapshotting might be back (not sure). I don't get any errors / feedback, so i'm not sure whether it's there or not. Could someone who's got it working before with any other version, please verify on Tools v26. Thanks. – Irvin H. Apr 10 '17 at 12:47
  • @IrvinH. Indeed, it is there, according to `help avd snapshot `, but I am not able to correctly save the emulator state, as `avd snapshot list` doesn't show anything after saving a snapshot. – Marcel Korpel Jul 26 '17 at 00:47
12

Based on one of the top answers I've found this working solution:

adb emu avd snapshot save foo

And especially it is very useful together with this one:

adb emu avd snapshot load bar
Roman Syrchin
  • 121
  • 1
  • 4
  • Full, up-to-date, information on this process is at https://developer.android.com/studio/run/emulator-snapshots. – Bink Apr 12 '23 at 19:21
3

Right. Assuming you checked "Enable Snapshot" while creating the avd, simply closing the emulator saves its state and is restored on the next run, be it from the manager or from eclipse.

Karthik C
  • 481
  • 1
  • 6
  • 15
Gaurav
  • 391
  • 1
  • 3
  • 7
2

For shell users, if you're running a --no-window emulator: It looks like using kill -2 to signal the emulator process will save the default boot snapshot, assuming you created the emulator with the --snapshot option.

Do this:

killall -2 emulator64-x86

The next time you boot that emulator, launching with anything but the -no-snapshot-load option will restore from that snapshot.

Yoni Samlan
  • 37,905
  • 5
  • 60
  • 62
2

I don't know is there any option available to restore from.

But you can save your emulator's current snapshot

Change your view perspective from Java to DDMS . By clicking the button encircled in red you can save a copy your emulator's current snapshot

enter image description here

Karthik C
  • 481
  • 1
  • 6
  • 15
Tanmay Mandal
  • 39,873
  • 12
  • 51
  • 48
  • Thanks for the additional info Tanmay. The button you circled helps take a screenshot :) and thats helpful too. What I meant is "saving/restoring" the "state" of the emulator. An feature rolled out just yesterday. Try it out! – Gaurav Jan 30 '11 at 12:29