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
Jan 20, 2009
How to pause and resume the activity?
View 3 Replies
View Related
Aug 28, 2009
I am learning about OpenGL and managed to write a prototype game using VBO buffers. If I start the application from Eclipse or adb, everything works fine until I press the back or <Home> button. If I restart the application either by a long press on <HOME> and selecting my program or by restarting it from the applications, I sometimes get a black screen and the LogCat shows this error:
CODE:...............
I am aware that it is probably a wrong setting in my program's flow, but I am not fluently enough with OpenGL.
View 10 Replies
View Related
Jul 30, 2010
I'm calling this tasks:
CODE:.........
And here are the two TimerTasks:
CODE:........
As you can see, I just call a method after 5 resp. 10 seconds. From time to time I would like to pause the "countdown". This means i want that the time until the 5 seconds are passed isn't running anymore. And then in a later point in time, I would like to resume it. How can I achieve that?
View 1 Replies
View Related
Sep 29, 2010
I suspect this will only have been noticed by people who listen to audio books!
After pausing playback (standard music app) then coming back to it a number of hours later, playback resumes a minute or 2 back from where it was paused. Which is rather annoying!
Guess a different music app might help, but I'm otherwise happy with the standard player... Anyone else come across the same issue?
View 7 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
Sep 1, 2010
I am getting data from the server using AsyncTask. I need to update the data periodically.
View 3 Replies
View Related
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
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
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
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
Jan 22, 2009
I'm having this problem with one of my apps where some people are reporting that their preferences are not being saved when they close and resume the app. The preferences theyre talking about happen to be actual Preferences (i.e. the built-in preferences manager for an activity). They say they're not doing anything special, just exiting the app and going back to it. Does anyone know why the prefs wouldn't be saved for only this select few people? I'm at a complete loss.
View 10 Replies
View Related
May 6, 2010
I am writing a simple android application with a class that extends activity, that plays a video from a url on the web. There is a button on top that on click takes the user to a web page.
What I want to do is when the user is browsing the web page, if he hits the back button, I want him to come back to the main activity and restart the video. Is there a way to do this?
Also, is there a way the video can be resumed from where it left off?
View 1 Replies
View Related
Jan 22, 2010
I'm currently working with a two-activity application. The first activity allows the user to choose options for their upload, and the second activity displays a ListView of their results once processed.I have code in place that performs the uploads/downloads in the background, regardless of whether the application is currently in focus or not (thanks to Matthias Kaeppler's Droid-Fu).I would like to have my application Resume into my second (results) activity when a user clicks on the icon from the top-level launcher, regardless of how long they have been away from the app. I thought that the 'alwaysRetainTaskState' flag in the Manifest would do it, but I've not had success with that. Can anyone tell me how I need to set up my Manifest to get this functionality?
View 19 Replies
View Related
Mar 10, 2010
I wanted to know if it is possible to Detect in an Activitiy's OnResume if the Activity is resuming because the devices Back button was hit or not?
View 5 Replies
View Related
Jul 22, 2010
What I have here is a simple webview activity that when loaded it auto displays an ongoing notification. The idea is that people can navigate away from this activity and quickly access it again from any screen they want by pulling down the drop down menu and selecting it. Then when they want they can just close the notification by hitting the menu button and hitting exit and then the notification clears. This all works fine. However, when the notification is pressed it starts a new instance of the activity. What would I have to change to make it see if the activity has not already been destroyed and I can just call that instance back(resume it) and therefore not needing to load it again and won't need to add another activity to my stack.
package com.my.app;
import com.flurry.android.FlurryAgent;
import android.app.Activity;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.webkit.CookieSyncManager;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Toast;
public class Chat extends Activity {
private ProgressDialog progressBar;
public WebView webview;
private static final String TAG = "Main";
private NotificationManager mNotificationManager;
private int SIMPLE_NOTFICATION_ID;
@Override
public void onStart()
{ super.onStart();
CookieSyncManager.getInstance().sync();
FlurryAgent.onStartSession(this, "H9QGMRC46IPXB43GYWU1");
}
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.chat);
mNotificationManager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
final Notification notifyDetails = new Notification(R.drawable.chat_notification,"ChatStarted",System.currentTimeMillis());
notifyDetails.flags |= Notification.FLAG_ONGOING_EVENT;
Context context = getApplicationContext();
CharSequence contentTitle = "Chat";
CharSequence contentText = "Press to return to chat";
Intent notifyIntent = new Intent(context, Chat.class);
PendingIntent intent = PendingIntent.getActivity(Chat.this, 0;
notifyIntent, android.content.Intent.FLAG_ACTIVITY_NEW_TASK);
notifyDetails.setLatestEventInfo(context, contentTitle, contentText, intent);
mNotificationManager.notify(SIMPLE_NOTFICATION_ID, notifyDetails);
CookieSyncManager.createInstance(this);
CookieSyncManager.getInstance().startSync();
webview = (WebView) findViewById(R.id.webviewchat);
webview.setWebViewClient(new chatClient());
webview.getSettings().setJavaScriptEnabled(true);
webview.getSettings().setPluginsEnabled(true);
webview.loadUrl("http://google.com");
progressBar = ProgressDialog.show(Chat.this, "", "Loading Chat...");
}
private class chatClient extends WebViewClient {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
Log.i(TAG, "Processing webview url click...");
view.loadUrl(url);
return true;
} public void onPageFinished(WebView view, String url) {
Log.i(TAG, "Finished loading URL: " +url);
if (progressBar.isShowing()) {
progressBar.dismiss();
} } }
public boolean onKeyDown(int keyCode, KeyEvent event) {
if ((keyCode == KeyEvent.KEYCODE_BACK) && webview.canGoBack()) {
webview.goBack();
return true;
} return super.onKeyDown(keyCode, event);
} @Override
public boolean onCreateOptionsMenu (Menu menu) {
super.onCreateOptionsMenu(menu);
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.chatmenu, menu);
return true;
} @Override
public boolean onOptionsItemSelected (MenuItem item) {
switch (item.getItemId()) {
case R.id.home:
Intent a = new Intent(this, Home.class);
startActivity(a);
return true;
case R.id.closechat: mNotificationManager.cancel(SIMPLE_NOTFICATION_ID);Intent v = new Intent(this, Home.class);
startActivity(v);
return true;
} return false;
} public void onStop() { super.onStop();
CookieSyncManager.getInstance().sync();
FlurryAgent.onEndSession(this);
} } @Commonsware
Just to be sure I have it correct, is this what you were suggesting? I was a little worried about this line:
PendingIntent.getActivity(Chat.this, 0, notifyIntent, SIMPLE_NOTFICATION_ID);
public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState);
setContentView(R.layout.chat);
mNotificationManager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
final Notification notifyDetails = new Notification(R.drawable.chat_notification,"ChatStarted",System.currentTimeMillis());
notifyDetails.flags |= Notification.FLAG_ONGOING_EVENT;
Context context = getApplicationContext();
CharSequence contentTitle = "Chat";
CharSequence contentText = "Press to return to chat";
Intent notifyIntent = new Intent(context, Chat.class);
PendingIntent intent =
PendingIntent.getActivity(Chat.this, 0, notifyIntent, SIMPLE_NOTFICATION_ID);
notifyDetails.setLatestEventInfo(context, contentTitle, contentText, intent);
notifyIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
mNotificationManager.notify(SIMPLE_NOTFICATION_ID, notifyDetails);
CookieSyncManager.createInstance(this);
CookieSyncManager.getInstance().startSync();
webview = (WebView) findViewById(R.id.webviewchat);
webview.setWebViewClient(new chatClient());
webview.getSettings().setJavaScriptEnabled(true);
webview.getSettings().setPluginsEnabled(true);
webview.loadUrl("http://google.com");
progressBar = ProgressDialog.show(Chat.this, "", "Loading Chat...");
}
View 1 Replies
View Related
Jul 2, 2010
I've got an app that creates an intent for the last.fm android app in which it will start the "recommended" station for my account when i press a button. The trick i'm trying to figure out is how do i get the phone back to my app without the user having to navigate back manually? Once it start the last.fm intent it takes you to the playlist and i need it to resume back to my app automatically.
View 2 Replies
View Related
Feb 6, 2010
I've an App which performs a potentially large download in background thread. When the orientation changes or the keyboard is opened the App lifecycle system invokes the start/stop/pause/resume etc calls - is there any strategy available to resume the download rather than just set a flag so the new onCreate() knows it was interrupted and has to start it again?
View 2 Replies
View Related
Mar 11, 2010
I have an application where I navigate from Activity A to Activity B and back to A and then B. I want to resume the activity B (which has a Bundle passed to it ) from Activity A. The documentation says that OnSaveInstance() is called only when the activity is killed, so how do i use OnPause which does not have the Bundle to resume the activity B.
View 13 Replies
View Related
Jul 23, 2009
I have an activity that is showing a video and when the user clicks a button, a new activity is launched. When the video activity stops, I pause the video view. When the video activity starts up again, I try to resume the video view videoView.start(), however, the video starts over from the beginning. I'm thinking that the buffer must be lost somewhere, so I now try to capture the current position via videoView.getCurrentPosition(), however, this is always returning 0.
Anybody know how to resume video playback when an activity starts up again?
View 5 Replies
View Related
Jan 13, 2010
I've got an activity that calls a helper class called DownloadManager. DownloadManager spawns a thread that downloads a mp3 to the sdcard. I'm having some trouble finding the best design for resuming the initial activity and starting the MediaPlayer. Does it make the most sense to use a BroadcastReceiver that receives a message that download is complete, then start a new Intent of my activity? Think I saw something that I can't use an Intent to start an Activity from BroadcastReceiver because it is a background process.
View 4 Replies
View Related
Apr 24, 2014
I really like Smart Launcher and I'm just done customising it but everytime I open an app it just starts from the start.
I'm reading some stuff in Reddit Sync, I press the home button to quickly check another app and when I go back to Reddit Sync (or any other app) it doesn't resume from where I left. Of course I can open up my recents and go from there but I'm wondering if this behavior is normal?
I'm on a LG G2 4.4.2 by the way.
View 2 Replies
View Related
Apr 9, 2010
If changing the orientation of my phone or the emulator I get the following output in LogCat:
04-09 11:55:26.290: INFO/WindowManager(52): Setting rotation to 1, animFlags=0
04-09 11:55:26.300: INFO/ActivityManager(52): Config changed: { scale=1.0 imsi=310/260 loc=en_US touch=3 keys=2/1/1 nav=3/1 orien=2 layout=18}
04-09 11:55:26.460: INFO/UsageStats(52): Unexpected resume of client while already resumed in client
04-09 11:55:26.579: INFO/SearchPosition(807): Activity is paused
04-09 11:55:26.689: INFO/SearchPosition(807): Activity is resuming
SearchPosition is the activity that is displayed. Activity is paused is written in the onPause Method and Activity is resuming in the onResume method of the activity. I googled a little bit for the error message but I don't fully understand the meaning of it. I think it could mean that the old Activity is not properly destroyed after changing the screen orientation. Is this correct? If yes what causes the error? If this is not correct? What is the meaning of this output?
View 1 Replies
View Related
Oct 3, 2010
Several of my Android applications show the following type message in the logcat output:
I/UsageStats( 59): Unexpected resume of com.totsp.test while already resumed in com.totsp.test
In this case I created the default Hello World app by letting the ADT tool generate it, and it still gets this message. I am not doing anything special in onCreate and don't even have any other methods defined.
I realize this is an INFO level message, and it doesn't appear to hurt anything, but I was curious what was going on so I made a test application that keeps track of the onResume invocations. It is indeed re-resuming when this occurs. I'm wondering why this this occurs? While I haven't noticed a problem (other than these annoying log messages), it seems like it could be using more resources than necessary to do all this stuff an extra time.
I have searched and read a similar question here on SO, and the answer there seems dubious to me: http://stackoverflow.com/questions/2606470/unexpected-resume-of-package-name-while-already-resumed-in-package-name-erro. Specifically, no, you don't want to use android:configChanges="orientation" because that is just subverting the orientation tear down/resume, rather than fixing it. Even the documentation notes "this attribute should be avoided and used only as a last-resort" (http://developer.android.com/intl/de/guide/topics/manifest/activity-element.html#config).
Also I have seen thread in the Android dev group where Mr. Murphy says the "unexpected resume" is "benign": http://groups.google.com/group/android-developers/browse_thread/thread/567410dbfcc163c2.
I'll dig into the source when I get a chance, but I figured I would first just ask the all-knowing hivemind and see if someone already knows: why does this occur, and is it truly benign?
View 1 Replies
View Related
Feb 20, 2009
I need to suspend/resume a thread from another thread in the same process. I tried to look into thread apis,but I couldn't figured out a way to achieve this.Can anyone pls point me some references to look or give a tip to do this.
View 2 Replies
View Related
Aug 27, 2010
I'm using SAXParser to parse large xml document from the net. And sometimes I need to pause SAXParser. I know how to stop parser by using SAXException, but how I can paused it? May be can I stop parser and then set up it to pass already parsed tags?
View 2 Replies
View Related
Oct 7, 2010
I am seeing an issue where when I hit the "back" button, I get the onPause call, but it isn't followed by onStop and on Destroy. On most phones, I see this, but on one particular phone (Droid-X),
View 7 Replies
View Related
Jan 13, 2010
Is it possible to use bundle and save the data in OnPause() lifecycle method? The scenario is i have 2 edit text and have entered some data i want to retain the data when the activity is killed and started again. his can be achieved using onSaveInstanceState() but as documentation says, this method is not a lifecycle method and hence the callback is not guaranteed. So i wanted to know if there is a way to save it using Bundle in onPause().
View 5 Replies
View Related
Feb 25, 2010
I have a loop which draw a bitmap for(int i=0;i<10;i++){
Here I draw a bitmap which will move to right a little bit in each loop.
I want a pause here so that an animation can be made.
View 2 Replies
View Related
Feb 5, 2010
I have an application that plays music. I want the application to get notified when the user plays a YouTube video so that I can pause the music in my own app. Is there a listener I can setup or a Broadcast receiver that I can setup to get notified of when the video is played.
View 3 Replies
View Related