Android :: How To Manage Background Task
Nov 9, 2010
I have a task which I need to run in the background in my Android app. It reads data over the network and populates a database. It can take several minutes to run.
Once it's started, it needs to complete successfully without interruption. (Otherwise I'll end up with a broken half-populated database.) I realise I can never guarantee it will always complete, but I want to make it as hard as possible for the system to kill off this task. For safety I guess I will have it populate a temporary database, and then only swap out the old database for the new one on successful completion of the import.
It's a modal operation; it does not make sense for the user to be interacting with the app while the import is in progress.
My first attempt is using an ASyncTask with a Progress dialog to achieve the modality, but this obviously breaks the "don't interrupt" requirement. I could work around the screen-rotation issue with ASyncTasks, but I don't think that goes far enough.
At the moment I'm not sure if this should be an ASyncTask, a Service, an IntentService, some combination of these, or something else entirely.
View 2 Replies
Nov 3, 2010
When I'm back from the background, onResume() method is called. Okay. So if I want to do some special code when I'm back I can put it there.
What about if I've many activities ? Do I've to duplicate that code everywhere ? Should I used the Application class and call a method in each onResume() methods ?
Plus, I would need to access the UI (changes, dialogs, ...). Maybe the application class isn't that a good idea ... ?
Concretely, I want to refresh my cache every XX time and I want to do that check when the application (or activity) is back from the background but I don't know exactly how to do and where to do that.
View 1 Replies
View Related
Jan 14, 2010
There seems to be a couple of ways to go about having a background task being executed. My usecase is to have my app fetch a datafeed every x minutes, regardless of my gui is running, and regardless of whether the phone is sleeping or not. I use an alarmmanager to schedule an intent matching a broadcastreceiver. in the onRecieve method i start a service (startService), which spawns an AsyncTask. The task fetches data and stores it and then stopSelf() the service.
in the onRecieve method i aquire a PARTIAL_WAKE_LOCK, before starting the service, and just before calling stopSelf() in the service, i release it again. Is this really the best way to do it? Do i even need the service in this scenario? I experience odd behaviour with this setup, where the setup works for hours and then suddenly stops, which makes it very hard to debug. Does anyone have a simple foolproof method to achive the same end?
View 1 Replies
View Related
Aug 31, 2009
I'm trying to run a background task which runs every minute or so for an android application but I am struggling to ensure that the task actually runs every minute. I've tried a variety of approaches from using SystemClock.sleep() to the AlarmManager (both repeating alarm and a fixed alarm) but it seems that unless the device is charging any kind of repeating system has a variable repeat rate once the device is unplugged. Is there any way to run a stable consistently repeating service?
View 2 Replies
View Related
Jul 16, 2010
I have an application which requires a login at the beginning (this is the first activity). When the user logs in, I keep his credentials in the application (I extended android.application to add a field called 'key'). I would like to clear this field from memory (from application instance) an go back to the login activity.
I see the following possibilities: - Add a broadcast receiver to catch all possible event (call, click on menu, click on back, lock the phone ...) which clear the key field and launch the login activity - Use clearTaskOnLaunch for all activities except the login activity. But then until my application takes the focus again the key stays in the application object. (It seems it doesn't work with the go back button, maybe I need to use no history also) - Detect for each activity in all onPause or onStop events when application will leave the foreground to clear the key field and launch the login activity
The best would be to have a kind of OnPause method at application level but I think it doesn't exist.
View 9 Replies
View Related
May 5, 2010
When I kill tasks in ATC and then hold the home button, it still shows apps running. What's up with that?
View 10 Replies
View Related
Aug 4, 2010
Say that the user has started my App and then switched off to use the Browser (so we have 2 sets of Tasks running). After a while, something happens to my app that requires the user's attention, so it posts a notification to notify the user. Is there a way to bring my App's task (and the Activity on top of the stack) out from the background when user clicks on my notification?
View 2 Replies
View Related
Jul 23, 2010
The official documentation describes tasks as follows: All the activities in a task move together as a unit. The entire task (the entire activity stack) can be brought to the foreground or sent to the background. Suppose, for instance, that the current task has four activities in its stack three under the current activity. The user presses the HOME key, goes to the application launcher, and selects a new application (actually, a new task). The current task goes into the background and the root activity for the new task is displayed. Then, after a short period, the user goes back to the home screen and again selects the previous application (the previous task). That task, with all four activities in the stack, comes forward. Is there a way to programmatically detect when the task of the current Activity moves into and out of the background? I would like to know when the user has switched switched to another application, vs. when the user navigated to another Activity in the current app.
View 2 Replies
View Related
Jan 30, 2010
I wish to have one application that runs in the background, which knows when any of the built-in applications (messaging, contacts, etc) is running. So my questions are: How I should run my application in the background. How my background application can know what the application currently running in the foreground is.
View 4 Replies
View Related
Sep 29, 2010
I download some data from internet in background thread (I use AsyncTask) and display a progress dialog while downlaoding. Orientation changes, Activity is restarted and then my AsyncTask is completed.I want to dismiss the progess dialog and start a new Activity. But calling dismissDialog sometimes throws an exception (probably because the Activity was destroyed and new Activity hasn't been started yet).What is the best way to handle this kind of problem (updating UI from background thread that works even if user changes orientation)? Did someone from Google provide some "official solution"?
View 1 Replies
View Related
Apr 24, 2010
I've got an Android activity which grabs an RSS feed from a URL, and uses the SAX parser to stick each item from the XML into an array. This all works fine but, as expected, takes a bit of time, so I want to use AsyncActivity to do it in the background. The line items = parser.getItems() works fine - items being the arraylist containing each item from the XML. The problem I'm facing is that on starting the activity, the ProgressDialog which i create in onPreExecute() isn't displayed until after the doInBackground() method has finished. i.e. I get a black screen, a long pause, then a completely populated list with the items in. Why is this happening? Why isn't the UI drawing, the ProgressDialog showing, the parser getting the items and incrementally adding them to the list, then the ProgressDialog dismissing?
View 3 Replies
View Related
Mar 27, 2010
I have an HTC eris and lately I've been having an issue with atm. Every time I have it kill my tasks it takes me to the HTC screen (the one that appears during start-up) and then "please wait" appears with my wallpaper in the background. It does still kill the tasks however it has never done this before and it seems abnormal. Ive heard that task managers can be bad for your phone?
View 10 Replies
View Related
Aug 25, 2012
I'm writing an android program for adding task and deleting task in listview. I've add an onClickListener to the delete button so it can delete the task. However I was told I should not have the listener in the adapter violating mvc. how I can remove a task in my TaskListItem class. I got the method removeTask() in the adapter, but don't how I can use it in the TaskListItem class.
Code:
public TaskListItem(Context context, AttributeSet attrs) {
super(context, attrs);
mContext = context;
[code]...
View 1 Replies
View Related
Dec 12, 2009
Is there an app for choosing which apps you want to use that are already open or whatever. Or is there a button you can press to bring up a task list like you do with you blackberry when u hold the blackberry key and the list of open apps comes out.
View 5 Replies
View Related
Dec 27, 2009
Automatic task killer, advanced task killer, or something else?
View 18 Replies
View Related
Nov 7, 2009
I've been using Task Panel X and Advanced Task manager to kill unneeded tasks and keep memory at a maximum.
Recently, every time I open Task Panel X and then revert back to Home screen I get the HTC logo and then a loading screen while the device sets itself. This happens even if I kill NO tasks.
So my solution was to uninstall Task Panel X and then use just Advanced Task Manager. All the sudden, same result.
Everytime I open either of these apps and then go back to home screen I get a BLACK SCREEN WITH HTC LOGO, THEN A BRIEF (10 SECONDS) LOADING SCREEN. THEN ALL IS NORMAL.
View 7 Replies
View Related
Dec 11, 2009
I know this was talked about before at different times but I still have 3 questions.
1. what is the difference between a task killer and a task manager?
2. should we be using one of these apps or not?
3. when you look at the awake time if it is like 70% or 80% and you aren't using the phone a bunch I take it that means something is running,how can you find what is running.and is the awake time that big of deal?
View 27 Replies
View Related
Oct 15, 2009
Looking for a guide on how to use task killer. I had task killer on and deleted it. I think I was killing tasks that were needed to keep certain functions running that I use frequently. If someone would take the time to help me understand how to use one, I think I would be much more successful with it.
example - text messaging just stopped ( werrent receiving them ) . Once I took task killer off, everything started working again.
View 7 Replies
View Related
Aug 22, 2009
Anyway, I just wanted for everyone to post their favorite Task Manager/Killer, and why, and if there are any flaws. I personally use Advanced Task Killer Free. It has a simple UI, and the when you select or unselect apps it remebers it so next time you launch the app you can only remove the apps that you usually do, and keep ones that always run. It doesn't slow down or break the system.
View 40 Replies
View Related
Sep 9, 2010
Has anyone used both. Ive heard that that Advanced Task Killer, still drains the battery. What about the Automatic Task Killer, which puts everything to sleep when not in use.
View 8 Replies
View Related
Nov 18, 2010
How to add a background theme and/or background wallpaper to my app? Right now my app background is plane.
View 2 Replies
View Related
Sep 8, 2010
I am new to Android development. I want to know how you all manage objects. For eg we make object as A a = new A(); and then manage that object. But, here, we call A.class; My concern is that i don't want to call on Create(),nor do i want to push UI screen I just want to make 1 static object for 1 screen;and want to manage it throughout my application. that is, instead of calling A.class; can i call A a = new A(),and manage that object without pushing,and whenever i need i push that screen. Is there someway?
View 1 Replies
View Related
Jul 24, 2010
i identified problem in changing one activity using tab, in on tab activity i am adding data to sqlite in other tab activity i am displaying them using listview(array adapter)but when i come back to add data and after adding new item to sqlite the newly added records are not updated in listview.
View 3 Replies
View Related
May 25, 2010
I want to start developing for android and for some reason whatever I do I can not make ADB show up my Nexus One. Both on and off in development mode. Both SD Mount and without SD Mount Both With USB tethering on and off for all "ADB devices"(windows XP64bit) show no device (service started successfully, device recognized in Device Manager correctly).
Tried reinstalling drivers, tried uninstalling drivers completely(using 3rd party software) and reinstalling, tried different versions of USB driver (up to the one before the last - that came with the 2.1 SDK). It seems online that this issue reoccurs on different devices, but all of them seemed to solve with one of the above solutions, Which none worked for me. It does not look like a hardware problem, because everything else that is USB'ed works correctly.
View 9 Replies
View Related
Feb 13, 2010
What is the best way to manage contacts, can u download your contacts?
View 2 Replies
View Related
Sep 3, 2009
I want to use the same eclipse project to maintain only one source code (or two projects that refer to a generic project). My problem is that the names of the package have to be different on the market (eg: my.android.app.lite and my.android.app.pro). If the package names are differents, the generated java ressource files are differents (eg: my.android.app.lite.R.java and my.android.app.pro.R.java). So, the source files must point to differents R files according to the version (pro or lite) and I have to change all the import...
View 6 Replies
View Related
Jun 21, 2010
I would like to know what is the recommendation for socket connection management in Android?In our App we would like to be connected to a TCP/IP server when our app is in the foreground or paused. So, create a connection to a TCP/ IP server when the App starts basically, On Create of the launcher activity. However, we do not want to create a new connection and close connection every time an activity is created, paused, destroyed or orientation changed. So, we save the connection object in the App class and the activities will reuse the same connection.Question is when do I close it? I would like to close the socket when the App is "paused", "stopped" or "destroyed". The problem is these messages are not sent in the App context. How can I figure out if the App is in foreground or not? Even the "Terminated" event for an App is not guaranteed to be delivered. So, in that case how do I know when to disconnect?
View 2 Replies
View Related
Jul 10, 2010
I want to change how a gallery looks like. I want to add 2 jogs at each side, so looks like this:
http://omploader.org/vNHc2Yw/device.png
First approach was to add the "jogs" to the ImageAdapter (at the beginning and at the end) for the Gallery. The Gallery will show the items as usual, but It will apply the custom background and also if you specify spacing, you will get an ugly gallery. Also, I want the jog not to be centered as the others images. Then, I decided to download the whole api and modify the Gallery source in a way so to handle specially the first item and the last item of the adapter. But, I don't know how to compile the api alone. The Makefile in the root project will build 6gb of the whole android platform. If someone can explain me how to build just the API, I will be grateful.
The other approach was to compose Views. I thought to add ImageView's to the left and right corner and to be scrolled when needed, but when the Gallery capture the events I can't forward it to the holder of the ImageViews. So, I extend Gallery, and I override onScroll() like this:
super.onScroll(e1,e2,distanceX,distanceY); return false;
and also onTouchEvent() like this:
super.onTouchEvent(event); return false;
But unfortunately when I return false wihtin onTouchEvent() the Gallery does not scroll.
So, main questions are:
1) How can I compile the modified API to generete a MyGallery.class to be added to android.jar? If I modify the source code of Gallery.java I can manage the fill of the Gallery for the specific items I want (I already read the source code).
2) In other approach, Is it possible to handle one event by 2 widgets? If so, I could overlap the Gallery above a jog. The Gallery will scroll as he knows, and I will scroll as I want.
3) If those approachs are bad, what will you recommend ?
I don't get why the Gallery does not have this nice feature I want to implement, kind of: setBorders(left, right) and etc. The problem on extending Gallery, is that when you add a View (for instance, the "jog"), you specify a position. Gallery fills the gallery getting the Views of it container with: getChildAt(0) and getChildAt(numChildren -1) when filling to right and left, respectively. Then, it gathers the 'unseen' Views from the Adapter. So the added view (the 'jog') will be scrolled by Gallery, but when the view is no longer visible, the Gallery itself has no way to get back that view, as it's not in the Adapter.
View 7 Replies
View Related
Jul 7, 2010
I always hear that I don't need to use Task Killers as Android manages its own memory. However, I find that sometimes when I play emulators, killing tasks provides far better framerates.
View 2 Replies
View Related
Apr 2, 2010
in android application development, i frequently go through the word "CALLBACK" in many places. i want to know want it means to tell us technically. and how i can manage the callback of the applications.
View 2 Replies
View Related