android


Async Task Failure


In my activity i have designed a navigation drawer, so when i click on the fragment my activity hangs up like this :
myactivity http://imageshack.com/scaled/large/844/z5ta.png
It freezes for 5~6 seconds, so i want to display a spinning wheel.
I know i should extend AsyncTask but it didn't work!
Here's what i tried :
private void samsung{
// TODO Auto-generated method stub
Url = "/// ////////////// //////////// /////////////.php";
new loadSomeStuff().execute(Url);
}
And Here's my aSyncTask Class :
public class loadSomeStuff extends AsyncTask<String, Integer, String> {
ProgressDialog dialog;
protected void onPreExecute(String f) {
dialog = new ProgressDialog(Fragment9.this.getSherlockActivity());
dialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
dialog.setCancelable(false);
dialog.setIndeterminate(true);
dialog.show();
}
#Override
protected String doInBackground(String... params) {
// TODO Auto-generated method stub
beanClass.clear();
list.setAdapter(null);
String result = "";
InputStream isr = null;
try {
HttpClient httpclient = new DefaultHttpClient();
HttpPost httpost = new HttpPost(Url);
HttpResponse resposne = httpclient.execute(httpost);
HttpEntity entity = resposne.getEntity();
isr = entity.getContent();
} catch (Exception e) {
Log.e("log_httpconnection",
"error in http connection" + e.toString());
Toast.makeText(getSherlockActivity(), "No Connection",
Toast.LENGTH_SHORT).show();
}
try {
BufferedReader reader = new BufferedReader(
new InputStreamReader(isr, "UTF-8"), 8);
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
}
isr.close();
result = sb.toString();
} catch (Exception e) {
Log.e("log_json", "Error converting Result " + e.toString());
}
try {
JSONArray jArray = new JSONArray(result);
for (int i = 0; i < jArray.length(); i++) {
JSONObject json = jArray.getJSONObject(i);
beanClass.add(new BeanClass(json.getString("PhoneName"),
json.getString("ModelNumber"), json
.getString("PhonePrice"), json
.getString("imageurl")));
}
dbHelpersamsung.deletesamsunglebanonphones();
dbHelpersamsung.insertthephonessamsunglebanon();
} catch (Exception e) {
Log.e("lag_tag", "ERROR PARSING DATA" + e.toString());
displaylistviewsamsunglebanon();
}
return null;
}
protected void onProgressUpdate(Integer... progress) {
}
protected void onPostExecute(String result) {
list.setAdapter(new MyListAdapter(getActivity(), beanClass));
}
}
You have this
list.setAdapter(null);
And this
Toast.makeText(getSherlockActivity(), "No Connection",
Toast.LENGTH_SHORT).show();
Updating ui from doInbackground is not possible. Update ui in onPostExecute or you runOnUiThread

Related Links

Right align text in android Webview
Service v/w Gatt connection in Android BLE API
How can I start learning maths for machine learning? [closed]
Instrumentation testing an Android activity with intents in isolation
Creating new calendar under google account using Google Calendar API
Change PasswordToggle Gravity to the left (for RTL language)
TextInputLayout (TextInputEditText) NullpointerException when click the toggle button
Android Wifimanager.getConfiguredNetworks() returns null
Firebase Realtime Database Limit Exceed
Issue reading the content of a DatasnapShot obtained from the ChildEventListener() for Firebase
Cordova app crashes when using Chrome DevTools
Firebase Database Datasnapshot
How do I call Google Cloud Endpoints on Android without user Google sign-in?
Can't stop MediaPlayer when onBackPressed
Firebase Authentication java.lang.IllegalArgumentException: Given String is empty or null
AB Shutter 3 to launch an Android app when the screen is off / locked

Categories

HOME
search
scikit-learn
nunit
twig
jwplayer
composite-primary-key
gradient
alsa
limit
angularfire2
bing-maps
mod-security
project-intu
libc
enterprise-architect
eip
flatpak
selectize.js
parameter-passing
azure-powershell
alpacajs
atlassian-stash
google-content-api
template-engine
google-container-registry
identity-management
mapstruct
cfml
connector
simpleitk
symbols
microsoft-ocr
rubymotion
named-entity-recognition
inno-download-plugin
gmock
onload
spotipy
finagle
arduino-ide
yowsup
lubridate
searchkit
lint
imagenet
movilizer
xmldocument
nanoc
cnc
dtsearch
appdomain
monkey
trigger.io
offline.js
baidu
change-tracking
smartfoxserver
builtins
preprocessor
vulcanize
tinkerpop3
gcloud-ruby
invoke-sqlcmd
np-spring
maybe
custom-errors
boomerang
toran-proxy
oracle-spatial
rate-limiting
opserver
baasbox
ansi
zend-currency
rrule
xmltype
exceldatareader
packet-sniffers
named-parameters
functional-java
winginx
twitter-bootstrap-rails
gae-quotas
light
gd-graph
mbunit
ebay-lms
mysql-error-2013
sentestingkit
usertype
procedures
entity-attribute-value
automationelement
unattended-processing
vs-android
maven-1
jqueryform
nstokenfield
build-environment
wysiwym
leader

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App