Internet Connection Not Working If My App Runs On A Api 8 Emulator
Solution 1:
I'm pretty sure it's a proxy settings issue. Try explicit setting the proxy (obtain the values from Android System).
On a default HttpClient this would be:
HttpClientclient=newDefaultHttpClient();
//Get the default settings from APNStringproxyHost= android.net.Proxy.getDefaultHost();
intproxyPort= android.net.Proxy.getDefaultPort();
//Set Proxy params of client, if they are not the standardif (proxyHost != null && proxyPort > 0) {
HttpHostproxy=newHttpHost(proxyHost, proxyPort);
client.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);
}
HttpGetrequest=newHttpGet("http://www.google.com");
Solution 2:
Maybe internet is turned off in the emulator? There should be a little 3G icon at the top of it, try clicking F8, it turns it on and off.
Solution 3:
Guesses:
- "Proxy is set correctly" Try it without setting any proxy.
- try using another cpu instead of the intel atom
Solution 4:
If you are developing in eclipse, you can try
Window>Preferences>Android>Launch
Default emulator options: -dns-server 8.8.8.8,8.8.4.4
EDIT:
goto: run->run configuration-> android application
then select your project -> target, scroll down options page and paste -dns-server 8.8.8.8,8.8.4.4 to Additional Emulator Command Line Options
Solution 5:
Since network access works with the AVD's browser, I'd focus on other potential sources of the problem.
If I were you, I'd simply try to compile against API 8. When you do that, you will be pointed towards any methods and other constructs you use in your code which are not available for API 8. (You haven't provided all code, e.g. there could be something hidden in MyAdapter. Also, you haven't mentioned whether or not your catch
log message appears in the LogCat.)
The other aspect which may be worth looking at is that you're not using AsyncTask correctly, and it's going to behave differently on different API versions.
Depending on the API version, when you do not choose the Executor explicitly, your AsyncTasks will either run sequentially or in parallel, resulting in many or few http connections and also resulting in concurrent manipulation of your data structure.
You may manipulate your Adapter only on the main/UI thread. Otherwise, e.g. when the user scrolls through your list, the UI will call your adapter's getView() which may be interrupted by your AsyncTask modifying the very entry which is currently being processed by getView(), resulting in inconsistencies and/or crash.
You have tried to achieve this by manipulating lt
asynchronously and calling myAdap.l = lt
on the UI thread.
This is a nice idea, but it has two problems. First, on API 8, many AsyncTasks can run in parallel, while on API 17 it will only be one. Qoute:
Starting with DONUT, this was changed to a pool of threads allowing multiple tasks to operate in parallel. Starting with HONEYCOMB, tasks are executed on a single thread to avoid common application errors caused by parallel execution.
So on some versions of Android, you would encounter a race condition by which copies of lt
would be manipulated in parallel, resulting in data loss upon the assignment. If those were actual copies, that is -- they aren't. By manipulating lt
asynchronously while it is already assigned as the underlying data structure of your Adapter, you're breaking the rule of not manipulating UI objects asynchronously.
So you'll need to pass the fetched data from doInBackground
to onPostExecute
and update your Adapter's data structure there.
The two points I mentioned may not be the final cause of the problem but they could very well contribute to the observed behaviour, need to be addressed anyway and will make it easier to identify any other potentail root cause.
Hope this helps.
Update You may also be using the HttpClient in a wrong way. See for example here. Maybe not all combinations are (correctly) supported for all API levels (there were several bugs in the past). You may also want to read Android’s HTTP Clients.
Post a Comment for "Internet Connection Not Working If My App Runs On A Api 8 Emulator"