android-asynctask

How to update a TextView from within onPostExecute

ⅰ亾dé卋堺 提交于 2020-01-11 14:38:07
问题 Need help here, about onPostExecute. If I want to put the update on textView what should be the code and what should I do?. @Override protected Value[] doInBackground(Integer... params) { ApiClient apiClient = new ApiClient(API_KEY); Variable batteryLevel = apiClient.getVariable(VARIABLE_ID); Value[] variableValues = batteryLevel.getValues(); return variableValues; } @Override protected void onPostExecute(Value[] variableValues) { // Update your views here } 回答1: Do as follows, save reference

Can't create handler inside thread that has not called Looper.prepare() with AsyncTask

流过昼夜 提交于 2020-01-11 12:18:32
问题 I am trying to use the AsyncTask class on android but I have a problem. Here is my code: public void CheckIfUserIsLogedIn () { int userPresence = localDatabase.CheckUserPresence(); if (userPresence == 0) { setContentView(R.layout.main); new checkCountryAsync().execute(); } else { setContentView(R.layout.userlogedon); } } class checkCountryAsync extends AsyncTask<String, String, String> { @Override protected void onPreExecute() { super.onPreExecute(); } @Override protected String

Error: “Method getText() must be called from the UI thread, currently inferred thread is worker.”

限于喜欢 提交于 2020-01-11 10:30:02
问题 While working on the project i get an error on following Activity. 1. Login.java on following Line of code. Line: "String username = user.getText().toString();" Error: "Method getText() must be called from the UI thread, currently inferred thread is worker." This is my whole Activity Code. package com.example.mysqltest; import java.util.ArrayList; import java.util.List; import org.apache.http.NameValuePair; import org.apache.http.message.BasicNameValuePair; import org.json.JSONException;

progress dialog with asynctask

北城以北 提交于 2020-01-11 03:08:26
问题 i have 3 classes and the class called WebServiceCleint class is extending Asynctask and in doInBackgrnd() i m passing url and i m getting data from webservice. but i m calling this from another class's method called VerifyTeacherId. Now how can i show progress dialog??? where should i write the pg.show and pg.dismiss.??? public class WebServiceClient extends AsyncTask<String, Void, String> { private static final String base_path = "http://www.gdaschools.in/"; protected static final String

Periodically fetching data (polling) from the server in Android

做~自己de王妃 提交于 2020-01-10 09:01:54
问题 I working on the app where I get the data from the server using rest call and add it to the view. I get all the initial data correctly. I use AsyncTask for doing it. Now I want to periodically (say 2 mins) fetch the new data from the server and add it to view.Periodically fetching data (polling) from the server in Android. 回答1: You can checkout the AlarmManager class to do it. Intent intent = new Intent(this, MyAlarmManager.class); long scTime = 60*2000;//2mins PendingIntent pendingIntent =

Periodically fetching data (polling) from the server in Android

邮差的信 提交于 2020-01-10 09:01:51
问题 I working on the app where I get the data from the server using rest call and add it to the view. I get all the initial data correctly. I use AsyncTask for doing it. Now I want to periodically (say 2 mins) fetch the new data from the server and add it to view.Periodically fetching data (polling) from the server in Android. 回答1: You can checkout the AlarmManager class to do it. Intent intent = new Intent(this, MyAlarmManager.class); long scTime = 60*2000;//2mins PendingIntent pendingIntent =

How to perform database operations using Async Task

会有一股神秘感。 提交于 2020-01-09 19:21:01
问题 My application is getting stuck while performing database operation after googling for solutions it was suggested that I use AsyncTask so that main thread doesn't get blocked. I have created seperate class and extended SQLiteOpenHelper and implemented "OnCreate" and "OnUpgrade" method. But to implement AsyncTask I need to extend "AsyncTask". Now my issue here is that I have already extended one class and I can't extend another class for the same class. My code is something like this. import

java.net.UnknownHostException: Unable to resolve host “<url>”: No address associated with hostname and End of input at character 0 of

倾然丶 夕夏残阳落幕 提交于 2020-01-09 01:59:09
问题 I've created an app that loads a question from my web services, and it works fine. But, sometimes it crashes and I do not get the reason why this is happening, especially because I have also given it the required permissions. It works fine, but at random, it crashes and gives me this report. private void sendContinentQuestions(int id) { // TODO Auto-generated method stub //Get the data (see above) JSONArray json = getJSONfromURL(id); try{ for(int i=0; i < json.length(); i++) { HashMap<String,

java.net.UnknownHostException: Unable to resolve host “<url>”: No address associated with hostname and End of input at character 0 of

半世苍凉 提交于 2020-01-09 01:59:07
问题 I've created an app that loads a question from my web services, and it works fine. But, sometimes it crashes and I do not get the reason why this is happening, especially because I have also given it the required permissions. It works fine, but at random, it crashes and gives me this report. private void sendContinentQuestions(int id) { // TODO Auto-generated method stub //Get the data (see above) JSONArray json = getJSONfromURL(id); try{ for(int i=0; i < json.length(); i++) { HashMap<String,

Implent an AsyncTask callback function returning multiple values?

ぃ、小莉子 提交于 2020-01-07 09:50:09
问题 I'm trying to understand how AsyncTask callbacks work. This is how my MainActivity looks so far: @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); MyAsyncTask AsyncTask = new MyAsyncTask(arg1,arg2,arg3).execute(); } And this is my AsyncTask class: public class MyAsyncTask extends AsyncTask<String, Void, Result> { private AsyncListener listener; public MyAsyncTask(AsyncListener listener) { this.listener =