Android :: Same Activity Called Twice - Multiple AsyncTasks?

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.

Android :: Same Activity called twice - Multiple AsyncTasks?


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 View Related

Android :: Starting Activity With FLAG ACTIVITY MULTIPLE TASK To See Multiple Instances

Feb 2, 2009

I am trying to launch an activity from another activity .. Within the com.android.SingleLauncher..

I have activity launch code as ..

CODE:...........

I have set the android:multiprocess="true" in the AndroidManifest.xml of TargetSL I don't seem to see the multiple instances of TargetSL, which i am expecting ..

All i see is 2 process, where i was hoping to see an instance of TargetSL, for each launch that was invoked by the singleLauncher!

View 3 Replies View Related

Android :: Retain Only One Copy Of An Activity On Stack When Called From Non Activity

Jul 26, 2010

How can I make sure I only retain one copy of an activity on the stack when called from non-activity? When called from an activity I can just add the FLAG_ACTIVITY_REORDER_TO_FRONT flag to the Intent, but how can I do this from e.g. a widget or a notification?

View 1 Replies View Related

Android :: How To Get Calling Activity Instance From Called Activity?

Jul 9, 2010

I have a Contact Activity which is derived from ListActivity, which displays list of contacts, and on click of item, a new Activity Message Activity derived from ListActivity is initialized.Now I know, I can pack some information in Bundle and pass it before creating activity, but is there a way I can get instance of "ContactActivity" in onCreate method of "MessageActivity"?

View 1 Replies View Related

Android :: LocationListener Being Called Multiple Times

Apr 16, 2010

I am working on an Location Based Application. In this application i am using LocationListener class to update the location when the Location is changed.In each Activity i have different LocationListener to update location and do some specific work on updated location. But my problem is that when i am changing my location through DDMS , the LocationListener is being called of that current Activity as well as all the activities of the whole application where LocationListener has been defined. I don't know whether there should be one LocationListener for the whole application or for each Activity we should have different LocationListener.

View 1 Replies View Related

Android :: Location Listener Called Multiple Times

Apr 16, 2010

I am working on an Location Based Application. In this application i am using LocationListener class to update the location when the Location is changed.In each Activity i have different LocationListener to update location and do some specific work on updated location. But my problem is that when i am changing my location through DDMS , the LocationListener is being called of that current Activity as well as all the activities of the whole application where LocationListener has been defined. I don't know whether there should be one LocationListener for the whole application or for each Activity we should have different LocationListener.

You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en

View 2 Replies View Related

Android :: SAX Is Getting Called Multiple Times With Same Data But Offset

Oct 27, 2010

I am trying to parse an xml file using SAX with Android and the problem is that the function characters(...) is getting called multiple times with what appears to be the same data just offset by a few characters.

As you can tell from the output below the first time it gets called with " alabama" and the second time it gets called with "labama". I am not sure as to why it is doing this but if anyone could help that would be awesome.

10-27 23:04:47.033: DEBUG/LocationHandler(10299):
10-27 23:04:49.000: DEBUG/LocationHandler(10299): alabama
10-27 23:04:51.835: DEBUG/LocationHandler(10299): labama
10-27 23:04:52.129: DEBUG/LocationHandler(10299): labama
10-27 23:04:52.408: DEBUG/LocationHandler(10299): labama
10-27 23:04:52.519: DEBUG/LocationHandler(10299): ub_dir_name
10-27 23:04:52.649: DEBUG/LocationHandler(10299): ub_dir_name
10-27 23:04:52.809: DEBUG/LocationHandler(10299): ub_dir_name
10-27 23:04:52.989: DEBUG/LocationHandler(10299): ile_name.kml
10-27 23:04:53.158: DEBUG/LocationHandler(10299): ile_name.kml
10-27 23:04:53.358: DEBUG/LocationHandler(10299): le_name.kml
10-27 23:04:53.529: DEBUG/LocationHandler(10299): le_name.kml
10-27 23:04:53.698: DEBUG/LocationHandler(10299): le_name.kml
Code...

View 1 Replies View Related

Android :: Is It Normal For OnCreate Method To Be Called Multiple Times?

Aug 27, 2010

I have some code in the onCreate method an Activity and noticed that it is being called three times. Is it normal behaviour?

View 1 Replies View Related

Android :: Pros - Cons Of Multiple Activities In An App Vs One Activity - Multiple Views

Aug 16, 2010

Are there design guidelines to help decide if an application with multiple views should be designed with multiple activities or just one activity and control the back button itself.

I've tried both. My most complex applications using one activity per screen. However, now that I'm successfully written an app with just one activity and handling the back button myself, I don't see any compelling reason to use multiple activities. The one activity application is much simpler and more straightforward.

What advantages of multiple activities am I missing?

View 8 Replies View Related

Android :: Shared Preference Listener Being Called Multiple Times When I Change A Pref

May 31, 2010

I've written an app with 3 tabs. Each tab has the same list view with different data sources. I have setup SharedPreferences in the tabhost activity, but I put my onSharedPreferenceChangeListener method in my listactivity. When I change a preference, my listener gets called and it updates my database. This is all working. However, if I change the data in tab 1, it calls my listener once. If I change the data for tab 2 it calls it twice and if I change the data in tab 3 it calls it three times. Any idea why it works this way? I guess I could setup my shared prefs in my listactivity and that might avoid the issue, but I'm curious why my listener is called multiple times if it's in a different tab.

View 1 Replies View Related

Android :: How Do I Know If Activity.onStop Is Being Called?

Dec 3, 2009

I need be able to tell if Activity.onStop() was called because my application is moving to a new activity, or if it was closed because the user pressed the "Home" key or hit the back button from the bottom of the activity stack.The reason is because I need to know when it is appropriate to shut off music that is playing in my application (A game). There is nothing more annoying than hitting home and having something playing music in the background.However, Activity.OnStop() is called for each activity change, and I don't want to suspend music when moving between multiple activities in my app. I just can't find a way to differentiate between going home and going to a internal activity.Am I perhaps hooking into the wrong events?

View 3 Replies View Related

Android :: Does OnActivityResult Get Called When An Activity Is Recreated

Sep 30, 2009

I have a flow A->B->C->D where A desires some information that is obtained by D. B, C, and D propagate the data back through the flow using setResult(RESULT_OK, data) and finish(). All intents in A, B, and C are started with startActivityForResult. However, if B is reclaimed by Android and forced to call onCreate again after C finishes onActivityResult in B is never called and the data never makes it back to A. Is there a way I can be sure that onActivityResult will be called?

View 5 Replies View Related

Android :: How To Clear Activity Stack If Using Same Activity Multiple Times?

Mar 3, 2010

So I have an app with Activity A. The layout on the activity is dynamic genearted. So it's possible that on Activity A a user hits a button that goes to "A" and the new page looks different, then a user clicks another button to go to "A" again. Now I have 2 Activities in the history stack. A, A, and currently on A. Is it possible that if a user clicks a button that the whole Activity stack is cleared in a scenario such as this?

View 5 Replies View Related

Android :: Image Capture Intent / Activity Not Get Called

Jun 26, 2009

I start an IMAGE_CAPTURE Intent like this, and my activity's onActivityResult() get called: Intent i = new Intent (android.provider.MediaStore.ACTION_IMAGE_CAPTURE, null); i.putExtra("return-data", true);
startActivityForResult(i, PICK_ICON_FROM_CAMERA_ID);
But, if I start my Intent like this, the Capture Image Intent did get called, but my activity's onActivityResult() never get called:
Intent i = new Intent (android.provider.MediaStore.ACTION_IMAGE_CAPTURE, null); i.putExtra(MediaStore.EXTRA_OUTPUT, Uri.parse("file:/" + "MyTestFile")); i.putExtra("outputFormat", Bitmap.CompressFormat.PNG.name());
startActivityForResult(i, PICK_ICON_FROM_CAMERA_ID);

View 3 Replies View Related

Android :: Activity Lifecycle On Nexus One - OnStop Not Called

Mar 4, 2010

I have a problem with the activity lifecycle specifically on Nexus One (2.1 running on emulator works fine). If I just create a simple empty Activity with no special launchModes that logs the calls on the onStart and onStop methods, this is what I see: - launch app: onStart called; - home button: onStop NOT called; - launch app: onStart NOT called; - home button: onStop NOT called: and so on. Sometimes if I press the back button then the onStop is not called, but the when i launch the activity again the onStart is called and right after the onStop is called. Similar results with different launchModes. What is going on? Can anyone confirm this?
i found an android issue for the problem here: http://code.google.com/p/android/issues/detail?id=6094 and a similar thread here http://groups.google.com/group/android-developers/browse_thread/threa.

View 24 Replies View Related

Android :: OnPause() Not Being Called For SingleTask Finish()'d Activity?

Feb 17, 2010

I'm not sure why onPause() is not called in the following scenario.

Here's my activity:

CODE:.......................

View 3 Replies View Related

Android : Webview - OnCreate Always Get Called When Activity Comes To Foreground

Mar 29, 2009

I launch my TestWebView activity. After my web page is loaded, I put the app in the background by pressing the Home key. Then I bring the TestWebActivity back to the foreground. Unexpectedly, TestWebView's onCreate() is called when I bring the activity to the foreground. But onDestroy is never called. This same thing happens every time I tested. It appears the old TestWebView was not completely killed so there are possibly duplicate web clients running.

My code: .....

View 7 Replies View Related

Android :: Parent Activity Runs OnCreate Before OnActivityResult Is Called - Sometimes

Aug 5, 2010

The order is:

A: startActivityForResult( B ) B: <dostuff>, call finish() A: onCreate <---- what's this all about A: onActivityResult

This happens for a tiny minority of users. I havn't been able to reproduce or find any common elements. A is the launch activity.

CODE:..............

View 7 Replies View Related

Android : Child Activity Exit By Unexpected Exception - OnActivityResult - Is Not Called

Jun 23, 2010

I have faced with issue about startActivityForResult() and onActivityResult(). If child activity started by the startActivityForResult() exit by unexpected exception the onActivityResult() is not called and I have no any ideas how can I handle this to get application working in a fail-safe manner ?

When my code runs child activity with startActivityForResult() it awaits until onActivityResult() will be invoked to get working further, but onActivityResult() is not calling and my code is "hang- up" (logically).

So the question is how can I handle all possible ways the child activity is finished (normally and by unexpected exception) to get fail-safe code ?

I have check the documentation for this issue but have found nothing relating issue.

View 4 Replies View Related

Android :: Voice Recognition Activity Called In OnCreate Method / Causes App To Load Slowly

Oct 1, 2010

In my android app I call the voice recognition in my onCreate method of my startup activity. I have made it a preference to start up with the voice control or not. However, the app takes about 5-7 seconds to load when voice recognition is on. When it is off, the app starts almost instantly. Below is sample code, I have added Free_Form, max_results 1, and a custom prompt to mine.Why would calling the normal android speech recognition take sooo long to load in my OnCreate method?

View 1 Replies View Related

Android :: Concurrency Of AsyncTasks

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

Android :: Periodically Executing AsyncTasks?

Sep 1, 2010

I am getting data from the server using AsyncTask. I need to update the data periodically.

View 3 Replies View Related

Android :: Pause And Resume AsyncTasks?

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

Android :: AsyncTask Preformance Issue On Many AsyncTasks Spawning

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

Android :: Super Slow Apps Caused By Large Number Of Unending AsyncTasks

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

Android :: Preference Activity / Multiple Preferences

Nov 4, 2010

Is it possible to use the PreferenceActivity and PreferenceScreen to manage multiple instances of preferences fro a single app? It seems that they store preferences as "default" preferences only. I would like to use a PreferenceScreen as my configure activity for an AppWidget, but I need to be able to store distinct preferences for each widget.

View 2 Replies View Related

Android :: Multiple Contact Selection Activity

Aug 30, 2010

Is it possible to get a multiple contact selection activity in Android?

View 1 Replies View Related

Android :: Activity With Multiple Repeating Backgrounds

May 13, 2010

I'm having trouble creating a layout with two backgrounds that tile in the x direction but not y.

I've mocked up what I'm trying to create here...

http://img153.imageshack.us/img153/6008/cnbackground.png

So the top section repeats horizontally, then there's a flat creen section in the middle in which I will center my content, then there's some horizontally repeating grass along the bottom.

View 1 Replies View Related

Android :: How To Create Multiple Instances Of An Activity

Feb 19, 2010

I want to create multiple instances of an activity in the same process. Should I use FLAG_ACTIVITY_NEW_TASK flag like the code below?

CODE:...............

This code is executed in class A to create another instance of activity A.

This question, will this code create another task? As I understand is a process can only have one task. Does it mean the two activities will exist in different tasks? That's what I want. I want the two activities to be in the same process.

View 1 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved