Stop Internet access on the emulator android
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,开发者_StackOverflow社区 stop internet access to force it using the database as a source to display data. Is that possible?
You can also use F8 to set the cell network on/off. See here
Disconnect your development machine from the network.
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.
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.
精彩评论