android-asynctask

Method setText must be called from the UI thread

岁酱吖の 提交于 2019-12-25 11:54:31
问题 Have read all the set and get called from the UI thread, on stackoverflow but none seems relevent. this code worked 2years ago, recently opened it. and it shows this error. "Method setText must be called from the UI thread". What updates are doing this? marked the setText lines with comments to make it more clear. Any sugestions? public class MainActivity extends Activity { static final String baseURL = "http://api.yr.no/weatherapi/locationforecast/1.9/?lat="; TextView dato, grader,

Android - Adding Columns to Matrix Cursor and Showing Column Count Toast causing Crash

浪尽此生 提交于 2019-12-25 08:48:17
问题 Im using a matrix cursor to add rows to cursor. Defined columns in the MainActivity on Create //In protected void onCreate String[] columns = new String[] { "dealername", "product","type","description","location","sublocation","address","phone1","phone2","auth","brands","lat","lon"}; cursor= new MatrixCursor(columns); //----------------- In asyctask doinbackground cursor.addRow(new String[] {json.getString("dealername"),json.getString("product"), json.getString("type"),json.getString(

Converting runOnUiThread to AsyncTask

不打扰是莪最后的温柔 提交于 2019-12-25 08:35:24
问题 I read in some links that i need to convert my runOnUiThread to AsyncTask: Android: RunOnUiThread vs AsyncTask But I am unable to get it done. I am implementing an AutoCompleteText which takes query from a database. My runOnUiThread along with the new thread (it compiles): new Thread(new Runnable() { public void run() { final DataBaseHelper dbHelper = new DataBaseHelper(ActivityName.this); dbHelper.openDataBase(); item_list = dbHelper.getAllItemNames(); ActivityName.this.runOnUiThread(new

Illigal character exception when making a remote server call using AsyncTask in Android

馋奶兔 提交于 2019-12-25 08:34:55
问题 I have this code: package com.problemio; import java.io.BufferedReader; import java.io.InputStream; import java.io.InputStreamReader; import java.util.ArrayList; import org.apache.http.HttpEntity; import org.apache.http.HttpResponse; import org.apache.http.NameValuePair; import org.apache.http.client.HttpClient; import org.apache.http.client.entity.UrlEncodedFormEntity; import org.apache.http.client.methods.HttpGet; import org.apache.http.client.methods.HttpPost; import org.apache.http.impl

Asynctask getActivity

女生的网名这么多〃 提交于 2019-12-25 07:58:40
问题 I am trying to set my toolbar title from an async task. I am getting a cannot resolve method getActivity() in this line: ((ActionBarActivity)getActivity()).getSupportActionBar().setTitle(name); My code looks like this: /** * Created by Mike on 2/28/15. */ import android.app.Activity; import android.app.Dialog; import android.app.ProgressDialog; import android.content.Context; import android.content.SharedPreferences; import android.os.AsyncTask; import android.preference.PreferenceManager;

skia decoder->decode returned false when download image and display in imageview

别来无恙 提交于 2019-12-25 07:46:29
问题 i have a php page which return image from php page in json format $result = mysql_query("SELECT image FROM image_table WHERE email_id = '$email'"); if (!empty($result)) { if (mysql_num_rows($result) > 0) { $result = mysql_fetch_array($result); $user = array(); $user["image"] = base64_encode($result["image"]); $response["success"] = 1; $response["image_table"] = array(); array_push($response["image_table"], $user); echo json_encode($response); } else { $response["success"] = 0; $response[

Android sensor registerListener in a separate thread

余生颓废 提交于 2019-12-25 07:21:18
问题 I have wrote a service to log accelerometer values in background. The idea is to register for sensor listener and write the values to storage. I have enabled the StrictMode.enableDefaults() in the MainActivity of the app (not in the service) to check if the service runs on its own thread. But it does not! I don't know what is the problem...I have this AsyncTask class that I hoped to take care of the problem but it apparently did not (this is inside the service and its execute method is called

Unable to add window Android dialog box

左心房为你撑大大i 提交于 2019-12-25 07:17:48
问题 First the user enter his username and password, then the app gets a list of data from an API. I'm trying to show a dialog box while the the app is synchronizing the data from an API, but I'm getting the following error: Log: ERROR 07-03 14:12:29.791 24439-24439/com.rep E/AndroidRuntime﹕ FATAL EXCEPTION: main android.view.WindowManager$BadTokenException: Unable to add window -- token null is not for an application at android.view.ViewRootImpl.setView(ViewRootImpl.java:571) at android.view

How to run this code in a Thread or Async Task?

自作多情 提交于 2019-12-25 06:41:19
问题 When I tried running this code I get an error, about the strictMode Thread policy, so I added this line. StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build(); StrictMode.setThreadPolicy(policy); I later discovered this is not the best approach that I have to run it in a Thread or an ansync task, so i will like to run it in a thread or an Asynctask. Please help edit my code when answering @Override protected void onCreate(Bundle savedInstanceState) { super

Getting OutOfMemoryError while loading images (as bitmap) from sdcard to gridview

时光怂恿深爱的人放手 提交于 2019-12-25 06:39:05
问题 I am developing an android app which contains lot of bitmaps and their processing. I was getting frequent out of memory crashes. I searched a lot for correct and standard way to load bitmaps and the best one I got here Loading Large Bitmaps Efficiently Now with this has reduced the frequency of crash but still there are some crashes to some specific area like, while displaying images stored in SDCARD to gridview, I am getting out of memory crash everytime even though I am using async task to