Android :: Running Multiple AsyncTasks At The Same Time - Not Possible?
Nov 1, 2010
I'm trying to run two AsyncTasks at the same time. (Platform is Android 1.5, HTC Hero.) However, only the first gets executed.
Here's a simple snippet to describe my problem:
CODE:................
The output I expect is:
onCreate() is done.
bar bar bar
foo foo foo
bar bar bar
foo foo foo
And so on. However, what I get is:
onCreate() is done.
bar bar bar
bar bar bar
bar bar bar
The second AsyncTask never gets executed. If I change the order of the execute() statements, only the foo task will produce output.
Am I missing something obvious here and/or doing something stupid? Is it not possible to run two AsyncTasks at the same time?
I realized the phone in question runs Android 1.5, I updated the problem descr. accordingly. I don't have this problem with an HTC Hero running Android 2.1.
View 1 Replies
May 8, 2010
I have three simultaneous instances of an AsyncTask for download three files. When two particular ones finish, at the end of onPostExecute() I check a flag set by each, and if both are true, I call startActivity() for the next Activity.
I am currently seeing the activity called twice, or something that resembles this type of behavior. Since the screen does that 'swipe left' kind of transition to the next activity, it sometimes does it twice (and when I hit back, it goes back to the same activity). It's obvious two versions of the activity that SHOULD only get called once are being put on the Activity stack.
Could this be from both onPostExecute()s executing simultaneously and both checking the flags each other set at the exact same time? This seems extremely unlikely since two processes would have to be running line-by-line in parallel...
A lot removed from this question since I was way off in what I thought was wrong. Nonetheless I found the answer here quite useful, so I have edited the question to reflect the useful parts.
View 1 Replies
View Related
Jun 23, 2010
I have developed a simple android application, which when started opens a Timer. User is given two buttons, start/ pause. This is working fine.What i want to do is to add a way to support multiple timers when a user swipes his finger on the screen.When he swipes from left to right, a new timer should show up, but the previous timer should not stop. This is a way to add multiple timers.Also, when he swipes from right to left, i want a previous timer to show.This is what i have done so for. I have a timer activity. I have added a touch event on it. When, a person swipes his finger, i get the co-ordinates and decide whether its from left to right or right to left.This functionality is working fine, as i can see the appropriate log messages.The problem is when I'm trying to load Timer Activity.It just loads the previous Activity and doesn't really create a new one (I figured this from the timer).Is there any way to do it?
View 1 Replies
View Related
Jun 26, 2009
I am replacing the multithreaded code in my app with the AsyncTask from 1.5. I found that two AsyncTasks do not work concurrently. I investigated a bit and found a workaround; I would like second opinion if my solution is right. OR if there is a better solution.
AsyncTask allows the app to do a task on a thread other than the UI thread. But IIUC, it only provides a single thread on which a queue of tasks is performed. Therefore, if one of the task is to wait on some event (n/w or sleep) then all other tasks will wait for it to finish.
To elaborate with the coding example: <code>
public class MyTask extends AsyncTask<...> { ... }
On the UI thread execute two tasks MyTask mt1 = new MyTask().execute(args);
MyTask mt2 = new MyTask().execute(args); </code>
In the above code both the execute calls will return immediately and free up the UI thread; however mt1 will be executed first and mt2 will have to wait until mt1 finishes.
Thanks to the android's open source, we can see implementation of AsyncTask. http://google.com/codesearch/p?hl=en&sa=N&cd=2&ct=rc#uX1GffpyOZk/core...
I copied AsyncTask.java as UserTask.java in my project and changed the value of CORE_POOL_SIZE to 5. This makes the thread pool to use 5 threads to multiplex the queued AsyncTasks. This indeed solved my problem. Now if mt1 blocks on a sleep; mt2 goes ahead and finishes its job.
Here are some questions for those who know more about AsyncTask implementation:
Is this work-around right? If yes, can the CORE_POOL_SIZE be made configurable in future, via an API call? Is there a solution by which multiple thread pools can be used?
Let me add that, I am aware that this is a phone and not a web server - I am not using 10s of threads to do network I/O. However a single thread is not sufficient for my app either.
View 5 Replies
View Related
Mar 3, 2010
I facing problem with multiple process running for my application. Can any one help me to avoid creating multiple process or restricting process creation to one.
Some times I am seeing two process instances of my package in the process list. I want to avoid this.
View 2 Replies
View Related
Oct 1, 2010
I have multiple activities in my android app and one final activity "All" which should run all the activities of my app one after the other. When I kept all my activities in for loop and used startactivity(intent) for each activity in that for loop, at the end I could see not all my activities being ran although all activities are finished. Any clue how to implement this?
View 3 Replies
View Related
Jun 27, 2009
This is what I have,say:
CODE:..............
All of the above is in single APK.
Instrumentation Runer used is - android.test.InstrumenationTestRunner itself.
This is what I am trying:
- I launched Emulator having above apk
- I opened three terminals , two to run instrumentation and third one to log results i.e.
CODE:...........................
Terminal 2:
CODE:...............................
Terminal 3: This is what I saw in the middle of logcat dump:
CODE:..........
Queries: 1. Is not it possible to run instrumentation in above manner? 2. I tried another TestSuite2 in terminal 2 instead of TestSuite1 , this also gave same results.
My aim is to run 2 testsuites parallel, using same apk. Is it possible? Or I have to use two different apks?
View 3 Replies
View Related
Sep 1, 2010
I am getting data from the server using AsyncTask. I need to update the data periodically.
View 3 Replies
View Related
Mar 19, 2010
I have an AsyncTask that acts as a countdown timer for my game. When it completes the countdown it displays the out of time end screen and it also updates the timer displayed on the screen. Everything works fine, except I need to be able to pause and resume this when the pause button in the game is pressed.
If I cancel it and try to re-execute it, it crashes with an IllegalStateException.
If I cancel it and instantiate a new AsyncTask in its place the old one begins to run again and the new one runs at the same time.
Is there a way to cancel/pause the timer and restart it using AsyncTasks or is there a different way I should be going about doing this?
View 3 Replies
View Related
Sep 4, 2010
When testing my app on a device I go through several "installs", although it's really the Eclipse plugin doing this for me.After a while (not very long) the device starts complaining about insufficient storage.It seems that progressive "re-installs" eats away the phone storage even though the app being installed (presumably) is either removed by Eclipse first or at least overwritten.Interestingly if I use a task killer to kill everything on the phone (which I only use for dev purposes btw),the available storage indicator recovers and I can keep working.As I said, it's more annoying than anything as the workaround.well works, but I'm wondering if there is some sort of cache chewing up storage?More importantly, I'm a little concerned that the same may happen with updates from the Market?That is, the update effectively replacing the current version of the app but leaving an allocation of storage behind in its wake.
View 5 Replies
View Related
Oct 11, 2010
How do I determine how long an application has been running? Is there a broadcast each time an app is launched and shutdown? I am trying to log the time spent using an application.
View 1 Replies
View Related
Jan 16, 2010
I need to have gps running all the time in my application, but I donīt know if it is better throw it like a thread inside of the activity or if I should creat a Service and then in the Service, throw the thread
View 5 Replies
View Related
Dec 28, 2009
I was wondering if anyone has come across a stop watch app that would let you set multiple time / countdowns. For example 60 seconds then 15 seconds then back to 60 seconds etc. This would be very useful for working out.
View 1 Replies
View Related
Apr 15, 2010
If anyone knows any good applications that can show multiple time zones in once glance. I'd like to know the current time for where I am as well as the time in my future destinations plus the current time back home.
View 6 Replies
View Related
Jul 30, 2010
I had a basic question. Can my class extend 2 or more classes at a time. What is the syntax. I want to extend Activity as well as Application. Wont this create problems in the manifest file? Activity because, I need to do a couple of things during the onCreate() [binding a service]and Application, because I am creating objects of another class [service class]which needs to be accessible throughout my application.
View 8 Replies
View Related
Oct 15, 2010
I am developing an android app w/ Eclipse.Whenever I run the app on my phone or the emulator, four application icons are installed on the device.I am guessing it is related to my manifest file which has three activities (3 are for tabs).When I uninstall the app, all of the icons are removed from the phone.Upon a reinstall, all four show back up.
View 2 Replies
View Related
Sep 19, 2010
I'm about to create a lazy image loader for images both from device and from the web for a ListView. I'm thinking of what to use and how, on one hand i can use a thread that pools my request (always running, and i can attach a view and an adapter and it will handle the image loading for me), cache my allready loaded images and checks for the visibility of the images before i load so i wont do unneeded job.
I had another thought of using the AsyncTask like many suggest in the forum. Terhe is one drawback though.I see that many use new MyTask().execute(urls); this presents a problem if i want to start loading and stop loading images on demand. If i use the async task per image then i need new async task for each image, that's a lot of 'new' to make, i can use a pool, but if too many async tasks are stuck, i will still create about 150-200 asyc tasks, too many for my taste...
What do you guys think ? i think a thread will do a nicer job here:
1. keep on running till killed
2. try to get a job from the queue, if not jobs, wait.
3. if a job is available, get it and start processing.
4. each request is processed alone,serially and blocks the thread.
5. once does goes on with '2'.
6. each enqueue that is done by the adapter using startLoadingImage() for views that need to be displayed will create anew job and call notify on the wait lock.
I can optimize this code with a pool of threads if i want several GETPOST requests in parallel. Also I'm caching the images i already downloaded loaded for fast load on next access. the idea is to minimize GC and list's slagging.
View 2 Replies
View Related
Apr 13, 2010
I am unable to use the following to code to play multiple sounds/beeps simultaneously. In my onclicklistener I have added
... public void onClick(View v) { mSoundManager.playSound(1);
mSoundManager.playSound(2); } ...
But this plays only one sound at a time, sound with index 1 followed by sound with index 2. How can I play atleast 2 sounds simultaneously using this code whenever there is an onClick() event?
public class SoundManager {
private SoundPool mSoundPool;
private HashMap<Integer, Integer> mSoundPoolMap;
private AudioManager mAudioManager;
private Context mContext;
public SoundManager() {
} public void initSounds(Context theContext) {
mContext = theContext; mSoundPool = new SoundPool(4, AudioManager.STREAM_MUSIC, 0);
mSoundPoolMap = new HashMap<Integer, Integer>();
mAudioManager = (AudioManager)mContext.getSystemService(Context.AUDIO_SERVICE);
} public void addSound(int Index,int SoundID)
{ mSoundPoolMap.put(1, mSoundPool.load(mContext, SoundID, 1));
} public void playSound(int index) {
int streamVolume = mAudioManager.getStreamVolume(AudioManager.STREAM_MUSIC);
mSoundPool.play(mSoundPoolMap.get(index), streamVolume, streamVolume, 1, 0, 1f);
} public void playLoopedSound(int index) {
int streamVolume = mAudioManager.getStreamVolume(AudioManager.STREAM_MUSIC);
mSoundPool.play(mSoundPoolMap.get(index), streamVolume, streamVolume, 1, -1, 1f);
} }
View 1 Replies
View Related
Sep 14, 2010
How to show two dialog at the same time? i don't to use Multiple Select at one dialog.
View 2 Replies
View Related
Nov 3, 2010
I have a application for listing student mark and name that is stored in raw resources ..res/raw. Can i change it from the code.
View 1 Replies
View Related
Apr 5, 2010
I want to have multiple listviews in single activity. But only one listview should be displayed at one time. The listviews will be loaded dynamically. So, how can I fill all the four listviews at the same time and display only one.
If anyone knows the solution then please share it over here. I hope to get a quick response.
View 1 Replies
View Related
Jun 4, 2010
It seems I have multiple programs that will start on their own and run in the background. The main ones are mp3 store, voicemail, sprint nav, sprint tv and qik. I haven't even ran those programs yet, but they're still starting up.
I went so far as to download ATK and kill them...only to see them running again 5 minutes later. I tried to put all the settings the same as what I had on my hero, but these running in the background are driving me nuts for some reason.
View 9 Replies
View Related
Aug 2, 2012
What I would like to do is to run 2 instances of an application or more. The issue is that I am using an RDP program that allows me to attach to a single connection, the kick is that I need the ability to toggle between those machines and the app does not do that natively. I can also see it being useful for a situation when you need to toggle between two documents that are both open with the same application.
I know that it is really not made to do this natively but if there is are ROMs that include that functionality or a way to alter android to do this. In addition, it would be great to be able to tell the system which applications can and can't function that way.
I currently have a nexus 7, transformer prime and transformer infinity to test this with.
View 3 Replies
View Related
Mar 3, 2010
When I connet device to DDMS sdk tool, I can see the running process.But I don't think that those process are tatal processes.For example, I have 10 android applications, A, B, C, D, E, F, G, H, I and J.If I want to run only A, B, C application on the power-on, how can I do that.?Where can I make a list for processes running in the poweron time.?
View 2 Replies
View Related
May 10, 2010
I don't use task killers or any nonsense like that, but I keep OS Monitor running so I can see if my CPU is running when it shouldn't be. While opening OS monitor and looking at my processes I noticed last night that there were like 6 flicker processes. They weren't currently using any cpu or anything, but why are there 6? And now today I noticed there are 2 running. (after re-start / battery charge)
View 3 Replies
View Related
Jun 24, 2010
Scenario: I turn my phone on and multiple applications are running in the background. I run Advanced Task Killer and close all applications in the background. I respond to a text message and all of a sudden FRING and QIK are running again? Why? Can settings be adjusted manually or do I need to Force Stop in Settings - Applications every time I turn on the phone?
View 1 Replies
View Related
May 2, 2010
I like to listen to live fire dept dispatch, and then be able to go to Google Maps, while the audio is still going, to look up addresses. Is there a way to do this? As soon as I leave the dispatch/web screen, the audio stops. How do I do this? I know there's got to be a way to have multiple apps going at the same time right.
View 1 Replies
View Related
Aug 11, 2010
I have no idea, but my app is stalling sometimes completely (not responding to touching the screen) I thought I was following all the rules for threading, but my app is apparently slowing down the Sprint EVO! I have never used an app as slow as my own. I don't get an ANR dialog, though I think I probably should get getting one. I have no idea how to make this application run like every other app I've ever used -- Not freezing. Is it not a good idea to have one HttpClient and keep a static reference to it for all Activities that want to use it? I used to create a new one each time, and thought that changing it to one sped it up. None of my AsyncTasks ever end. If I go to Activity A -> B -> C -> D the first time it will be smooth. I can press back but when I get back to A, its completely frozen, not responding to anything. That when I took that screenshot. I really have no clue what I am doing wrong. Should I manually kill my AsyncTasks on Activity.onPause()?
View 1 Replies
View Related
Jun 12, 2014
I have the galaxy S5 running 4.2.2
I hate having the phone wake up in my pocket after unlocking with either fingerprint or pin.
The phone is set to lock after 5 minutes of inactivity - but if bumped in the pocket, the phone wakes up without the swipe lock screen.
Is it possible to use a combination of two lock screen types?
View 3 Replies
View Related
May 5, 2010
For some reason if I open Advanced Task Killer I have like 8-12 apps running all the time. They're random too, many that aren't attached to widgets. An example is gesture search. I feel like this is eating up my battery.
View 13 Replies
View Related