intentservice

How to keep an IntentService running even when app is closed?

筅森魡賤 提交于 2019-12-04 22:38:25
In my Android app I start an IntentService from within an Activity by calling startService(new Intent(this, MyService.class)); And it works like a charm. I can move between Activies, press the Home button to switch to other apps... and it's still working. But if I remove my app from the recents screen, my service is stopped. How can I avoid this? In other words, how can I keep my service running even if my app is closed from recent apps? My service code is as follows: public class MyService extends IntentService { public MyService() { super("MyService"); } @Override protected void

Updating Activity UI from Intent Service?

百般思念 提交于 2019-12-04 19:25:39
I need to download some files (10-20 or depends on user) from service in my app. The problem is I am using IntentSevice and finding it hard to update activity UI. I know following ways to update UI Use handler and send messages from service to activity using Messenger like this . Send broadcast intents. Using first method would cause problem once activity is closed & re-opened and also I am not sure about its performance. Using second would definitely cause perfomance issues since I need to update UI quite frequently (once or twice every two seconds). Is there anyother possible way of

IntentService won't show Toast

≯℡__Kan透↙ 提交于 2019-12-04 15:22:48
问题 This IntentService I created will show Toasts in onStartCommand() and in onDestroy(), but not in onHandleIntent(). Am I missing something about the limitations of an IntentService? public class MyService extends IntentService { private static final String TAG = "MyService"; public MyService(){ super("MyService"); } @Override protected void onHandleIntent(Intent intent) { cycle(); } @Override public int onStartCommand(Intent intent, int flags, int startId) { Toast.makeText(this, "service

How to get Context in an Intent Service

ⅰ亾dé卋堺 提交于 2019-12-04 14:58:18
问题 Here's the scenario: I have a WakefulBroadcastReceiver that does a backup to a network computer or the cloud. It's set to go off in the middle of the night, when I know the tablet will have access to the LAN. The backup will store the data to a location and a file that was "picked" by the fragment that instantiated the WakefulBroadcastReceiver, using the Storage Access Framework. So I need to be able to access the ContentResolver and to do that I need the context. From all my reading of the

Android Download Multiple Files one after another and show progress in ListView

时光怂恿深爱的人放手 提交于 2019-12-04 12:40:26
The user can add any number of downloads, but download will start one after another i.e. next download will start only after the completion of present download. The user will navigate away from the activity showing download progress in order to add new downloads, and when new file to be downloaded is added, the application navigates back to the activity showing download progress, where it will show the progress of the download, previously added, and keep the presently added file as pending download. As soon as the downloading completes, pending download will start downloading. In this way the

Android LocationLister implemented in IntentService never execute the OnLocationChanged() method

故事扮演 提交于 2019-12-04 11:15:52
I've written an IntentService which implements the LocationListener interface. The service should send a message when OnLocationChanged() method was called at the first time. But OnLocationChanged() is never called. Here's my code: public class MyIntentService extends IntentService implements LocationListener { private int result = Activity.RESULT_CANCELED; protected Messenger mMessenger; protected LocationManager mLocationManager = null; public MyIntentService() { super("LocationService"); } @Override protected void onHandleIntent(Intent intent) { Log.i(TAG, "Got starting intent: " + intent

Should onHandleIntent be called when IntentService is started with bindService?

ぐ巨炮叔叔 提交于 2019-12-04 10:49:06
My service extends IntentService and when it is started with startService , onHandleIntent gets called. However, when the service is started with bindService (I do need binding), onHandleIntent does not get called. Should onHandleIntent be called when IntentService is started with bindService ? Is startService the only way IntentService should be started? The documentation for IntentService says the following: Clients send requests through startService(Intent) calls; the service is started as needed, handles each Intent in turn using a worker thread, and stops itself when it runs out of work.

How do I cancel all pending intents that are qued for intent Service

守給你的承諾、 提交于 2019-12-04 09:55:09
I have an intentservice that gets qued by the user and by my app automatically. I need to be able to kill all pending intents that are qued when the user logs out of my application, but I cannot seem to get that to work. I have tried stopService() and stopself(), but the intents continue to fire off the intentservice after the user has logged out. I would try to get the id of the intent but that is difficult as everytime the intentservice starts, the variable holding the intent id's is empty. Here is my intentservice code: public class MainUploadIntentService extends IntentService { private

Method onHandleIntent() does not get called

主宰稳场 提交于 2019-12-04 06:29:25
After many hours of researching I am finally consulting official help. Why does not onHandleIntent() get called? Is there something wrong here? In main activity onCreate() : mService = new Intent(context, xyz.class); startService(mService); That iss it. The onStartCommand() gets called, but not onHandleIntent() package com.autoalbumwallaperplus; import android.app.IntentService; import android.content.Intent; import android.widget.Toast; public class xyz extends IntentService { public xyz() { super("bmp"); } @Override public int onStartCommand(Intent intent, int flags, int startId) { Toast

Capturing IntentService Intents before onHandleIntent

ⅰ亾dé卋堺 提交于 2019-12-04 06:26:01
I have an IntentService which queues up web service calls to be made. I pass an integer as an Extra with each Intent which defines the type of web service call to be made. I'd like to create a situation where, if an Intent to perform a particular web service is passed to the IntentService and an Intent for that same web service already exists in the IntentService queue, the Intent is not processed. Ideally, I'd throw away the Intent, but I could also add an Extra to it that lets the code know to skip the Intent once it is handled. As Intents come in, I could keep track of which ones are in the