android-asynctask

What change did really happen in Async Task after Android Gingerbread?

廉价感情. 提交于 2019-12-31 03:32:08
问题 What change did really Android team make in Async task after android 2.3. When I executed the following code I am getting same result in both Android 2.3 and 3.0. package com.sample.asynctask; import android.app.Activity; import android.os.AsyncTask; import android.os.Bundle; import android.util.Log; public class AsyncTaskTestActivity extends Activity { private static final String TAG = "AsyncTaskTestActivity"; /** Called when the activity is first created. */ @Override public void onCreate

Threading in Android to process long running processes

别说谁变了你拦得住时间么 提交于 2019-12-31 02:08:08
问题 Ok, here is my problem. I want to learn AsyncTask, Threading and Handler to process long running tasks. I used Android Cook Book and New Boston Android tutorial, but I can't make it work. I need to change the progress bar message. This is not for project, but to learn threading. Threading is really hard for me. So if you have any tutorial or guide to understand threading please let me know. Meanwhile I tried Handler class, but it didn't work. So I tried AsyncTask. But it does not work either.

AsyncTask - what parameters are needed for extending and doInBackground?

强颜欢笑 提交于 2019-12-31 01:49:09
问题 What is wrong with this code that uses AsyncTask? In particular: - what parameters do I need to put in fetchSchools - what parameters do I need to put in doInBackground? I've found lots of "helpful" examples but they all use pseudocode in these parameters and don't explain what I actually need to put there. "I get the Eclipse error the method fetchSchools must implement the inherited abstract method AsynchTask..." I don't need to pass this anything, I expect it to return a string. public

Is it better to use AsyncTask or Service to upload a file in background?

痞子三分冷 提交于 2019-12-30 18:56:12
问题 I have a requirement where a user is able to upload a video to Amazon S3. I have achieved this using the java high-level api in amazon sdk. During the upload process if the user clicks the home button the upload must continue in the background. What would be a better approach :? *1 Using AsyncTask: I have tried using AsyncTask and it works fine. But if the uploading process continues for long interval at the background, the OS kills the app to free memory. Is there any way that i can handle

How to execute some code in Android UI thread async?

醉酒当歌 提交于 2019-12-30 17:39:10
问题 I'm new to Android development. I've be working on Swing and SWT for several years. Both Swing and SWT has a stratage to execute code in UI thread sync and async. The typical usage is doing some time-consume staff in one thread then display the result in UI thread async. So my question is, is there similiar stratage in Android? Here is my code. Parameter runnable is some time-consume code. This method will display a waiting dialog during the execution then EXPECT to show a Toast after it is

Android - setSoTimeout not working

前提是你 提交于 2019-12-30 14:08:27
问题 So I'm running into a not working socket timeout. I followed all instructions given by existing posts, but its still not working (I never get a socket timeout exception). Here is my code: AsyncTask<String, Void, String> task = new AsyncTask<String, Void, String>() { @Override protected String doInBackground(String... params) { String location = params[0]; try { HttpGet httpGet = new HttpGet(location); HttpParams httpParameters = new BasicHttpParams(); // Set the timeout in milliseconds until

App Crashes on AsyncTask Screen Rotation

坚强是说给别人听的谎言 提交于 2019-12-30 13:59:17
问题 I'm using AsyncTask in one of the fragments of an activity. The AsyncTask is working perfectly but on screen rotation, it loses the reference to activity and the variable returns NullPointerException thus the app crashes. I looked at similar questions like this, this, this, and this, but I don't think using config change hack is the solution. The code that maybe crashing the application (according to LogCat, the NullPointerException is at the following line): Context context = MyActivity.this

Downloading Image in android using asynctask for RecyclerView

一个人想着一个人 提交于 2019-12-30 11:53:51
问题 This my following AsyncTask class code for downloading image for RecyclerView . public class MyDownloadImageAsyncTask extends AsyncTask<String, Void,Bitmap> { private final WeakReference<ImageView> imageViewReference; public MyDownloadImageAsyncTask(ImageView imv) { imageViewReference = new WeakReference<ImageView>(imv); } @Override protected Bitmap doInBackground(String... urls) { Bitmap bitmap = null; for (String url : urls) { bitmap = MyUtility.downloadImage(url); /*if (bitmap != null) {

Is instantiating an AsyncTask from a WakefulBroadcastReceiver recommended?

一曲冷凌霜 提交于 2019-12-30 11:01:42
问题 I can instantiate an AsyncTask from WakefulBroadcastReceiver (see my motivation for favouring AsyncTask over Service), e.g., public abstract class AlarmReceiver extends WakefulBroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { new AsyncTask<Void,Void,Void>(){ @Override protected Void doInBackground(Void... v) { while (true) { SystemClock.sleep(7000); Log.w("", "alive"); } } }.execute(); } } But is this recommendable? In particular, are there life cycle

Real difference between AsyncTask and Thread

你离开我真会死。 提交于 2019-12-30 05:45:29
问题 I have been reading Android documentation (AsyncTask, Thread) and vogella tutorial about this matter, but I have doubts yet. For example, I want to send a message from an Android app to a server. And I would like this process to be responsive. What should I use? I have seen examples where they create a new Thread for not block UI, but this way we don't have the progress of process, also you have to process the response within the Thread because the run() method doesn't returning anything.