18

I am testing a database storage after retrieving data from the internet, I would like to be able to start the emulator with internet working, and then, while it is running, stop internet access to force it using the database as a source to display data. Is that possible?

4 Answers 4

37

You can also use F8 to set the cell network on/off. See here

4
  • Great guys, thank you very much for help. this one's better actually, because I can keep surfing while testing .
    – Sephy
    Feb 10, 2010 at 9:49
  • 17
    This does not work. The 3G icon disappears from the status bar but there's still internet connection.
    – rgngl
    Nov 20, 2011 at 9:51
  • It worked straight away for me. I don't know if you still have internet connection, but connectivityManager.getActiveNetworkInfo() says I don't, and that's what a developer should care about.
    – Maragues
    Jan 18, 2013 at 10:05
  • it's the simple things in life =]
    – kkemple
    Jan 9, 2017 at 22:14
7

Disconnect your development machine from the network.

3
  • 1
    Lol that's seems pretty easy. didn't even think of that. Cheers man!
    – Sephy
    Feb 10, 2010 at 9:08
  • 1
    This is not an option if you connect to services on your local machine, so problem is still opened.
    – Johnny
    Jun 7, 2012 at 9:49
  • This was a quick and dirty solution that actually worked for the OP before ccheneson gave a better solution, so everybody just relax. Oct 9, 2012 at 21:45
1

To test offline functionality in my Android emulator, I use the phone's settings to put the emulator in Airplane Mode, or shut off both cellular and WiFi.

0

Taking one step further the line of reasoning of disconnecting the development machine.

I've found, when faced with the same intent as the original question (test data persistence) that the easiest approach was to make my development server error out.

This approach has the extra benefit off making you think about dealing with server errors, since from the client standpoint being offline because of poor cellular network reception may be the same as i.e. the server being unreachable because of DNS configuration issues.

Of course it will not technically resemble airplane mode, or allow for any other complex connectivity testing based behaviour, but it may fit the same purpose.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.