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

How to stop action bar move up
Scrolling down leads to activate the pull down refresh option
Firebase notifications: activity doesn't launch when status bar notification is clicked
Remove item from SharedPreference when removed from Listview
Testing static methods in android
Gradle can't find standard React class
How to fix the internationalization error on Android?
Here Mobile SDK MapOffScreenRenderer performance problems
Layout issues on different screens
Android Studio Gradle compile not working
Android File.mkdirs() not working without error
Getting the same value for textStyle attribut in styles.xml
CloudOnce breaks in Unity 5.6
How to get current layout on android? [closed]
How to successfully compile NDK (c file) in Android Studio?
Progress Bar Android

Categories

HOME
windows
dns
mjml
angular2-material
zend-framework
toolbox
battery
serialization
camera
r-googlesheets
edge
aws-cli
tvos
jax-ws
boto3
drop-down-menu
vimdiff
redis-sentinel
3nf
heat
symfony-2.8
feathersjs
dreamweaver
easyphp
breadth-first-search
kendo-mobile
blade
jquery-ias
cgbitmapcontext
ios10.2
hta
event-store
beta
xunit
motion-detection
pylons
firebase-analytics
carrierwave
twiml
userdefaults
dotspatial
android-sugarorm
android-maps-extensions
mnist
imagenet
reactivekit
metaprogramming
metawidget
urlsession
watchface
android-softkeyboard
importerror
flask-login
vaadin-elements
lampp
vugen
launchctl
corruption
scalding
appdomain
modelsim
opengl-4
excel-dna
materialized-path-pattern
gets
tinkerpop3
flex4.6
dotnetnuke-7
mongodb-php
windows-azure-queues
hclust
xdoclet
lean
lua-telegram-bot
aspen
realsense
dynamics-nav-2016
microsoft-reporting
slash
atoi
omnifaces
entity-framework-4.3
document-repository
delayed-execution
functional-java
ecslidingviewcontroller
printdialog
pdfviewer
mkv
multiplexing
usertype
agility.js
saxparseexception
inline-formset
aspmenu
interprocess
zend-rest
pagemethods
build-environment
silverlight-oob
cuda.net
interop-domino
fault-tolerance
httpcookie
blind
idatareader

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