android-intentservice

Should I use Service or IntentService for my android app?

北慕城南 提交于 2019-12-12 08:29:17
问题 Please correct me If I am wrong : 1) A Service is used to perform long tasks in background. A service runs in the UI thread so if there comes a long task then it may freeze our UI. A service will continue to run independent of application as long as we tell it to stop. 2) An IntentService on the other hand is used to perform short tasks in separate thread. It automatically terminates when it finishes its task. What I have to do : 1) check for location every 5 seconds 2) if there is a change

onHandleIntent receiving the fired intent every second instead of every 30 seconds

淺唱寂寞╮ 提交于 2019-12-11 14:35:55
问题 I have checkboxlist where the user selectes some items I am envloping his selecting in json format thenI am firing the json string from the alarmManager to the GetLLRD class. Currently I am getting intent in the OnHandleIntent not every 30 second but roughly every second or several times in one second. How can I manage it to get the intent just once every 30 seconds in the onHandleIntent in the GetLLRD class? Some of the output: 07-07 17:18:01.817: I/System.out(6493): test from the

Interaction between IntentService and Activity - Android

跟風遠走 提交于 2019-12-11 11:41:24
问题 In my application I am using an IntentService to download a file from a cloud. And showing the progress in NotificationManager . I need to show the status (Downloading/Completed or Failed) in the Activity which stared the IntentService too. My problem is once I closed the app and open it back, I want to get the status of downloading from IntentService . Which is the best way to do this? 回答1: You can let your Activity bind to your Service, by calling bindService() in your Activity. As per the

ResultReceiver gives Nullpointer exception

你离开我真会死。 提交于 2019-12-10 20:01:58
问题 I am using Geocoding to retrieve addresses of latitude,longitude values. I'm implementing this GeoCoding in a seperate class extending IntentService. When I retrieve the address I want to send it back to the original main activity, and for this i use ResultReciever, and actually following the tutorial. This is the class that I use to GeoCode i.e. transfer GPS coordinates to physical addresses. I get error when invoking the function call deliverResultToReceiver in onHandleIntent public class

How to stop Service when app is paused or destroyed but not when it switches to a new Activity?

情到浓时终转凉″ 提交于 2019-12-10 15:38:40
问题 Currently I have a Service which I am using to play a sound file in the background whilst the app is open: public class BackgroundSoundService extends Service { MediaPlayer player; public IBinder onBind(Intent arg0) { return null; } @Override public void onCreate() { super.onCreate(); player = MediaPlayer.create(this, R.raw.sound); player.setLooping(true); player.setVolume(100, 100); } public int onStartCommand(Intent intent, int flags, int startId) { player.start(); return 1; } @Override

Starting service on boot to to do work every 15 minutes

核能气质少年 提交于 2019-12-10 12:19:41
问题 So, i have gone through internet looking for solution, but didnt find anything that combines what I need. I need this: if mobile gets restarted, I need to start a service on boot that will every 15 minutes send data to my server. I made code that is working for boot, but don't know how to implement timer. Do I need 2 broadcast receivers and 2 services or? My broadcast receiver: public class BrReceiver extends BroadcastReceiver { final public static String ONE_TIME = "onetime"; @Override

Oreo, default SMS App and ACTION_RESPOND_VIA_MESSAGE

大城市里の小女人 提交于 2019-12-10 10:08:07
问题 Applications targeting Android O have a couple of new rules when using services, one of them is that we can't start services while the application is in background. One of the requirements to be a default SMS application is: (from the Telephony.java javadoc) * <li>In a service, include an intent filter for {@link * android.telephony.TelephonyManager#ACTION_RESPOND_VIA_MESSAGE} * (<code>"android.intent.action.RESPOND_VIA_MESSAGE"</code>) with schemas, * <code>sms:</code>, <code>smsto:</code>,

OnHandleIntent() not called in IntentService

百般思念 提交于 2019-12-10 06:36:17
问题 I know this question has been asked before, but I've been over all of the answers I could find and still haven't been able to solve the problem. The issue is that when by BroadcastReceiver starts the IntentService onHandleIntent() isn't called. Weirdly enough the constructor does run (as I can see by the Log output). This is my code: NoLiSeA.class (This class contains the BroadcastReceiver that starts my service) public void toProcess(StatusBarNotification sbn) { LocalBroadcastManager

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

最后都变了- 提交于 2019-12-10 01:14:27
问题 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

Is IntentService appropriate for FileObserver

☆樱花仙子☆ 提交于 2019-12-08 07:53:34
问题 I need to set a FileObserver on a directory. The observation period is linked to a long running activity, long running because it has a ViewPager with a lot of pages. Instead of placing the FileObserver inside the activity, I was thinking of putting it inside a service. Now I am wondering would I use IntentService or should I roll out my own implementation of Service? My real concern is that I do not want the service to stop until I explicitly call stopService(intent). But I understand that