intentservice

IntentService onHandleIntent() still running after onDestroy() fired

非 Y 不嫁゛ 提交于 2019-12-06 02:46:58
In my preference screen, I want to start a service to download files from the internet when one of the preference is being clicked. If the service is already running (downloading files), then the service should be stopped (cancel download). public class Setting extends PreferenceActivity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); downloadPref.setOnPreferenceClickListener(new OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference pref) { if (DownloadService.isRunning) { Setting.this.stopService(new Intent

Does AlarmManager require the PendingIntent to be of Type BroadcastReceiver?

一个人想着一个人 提交于 2019-12-06 01:24:28
The documentation for AlarmManager seems to imply (but does not outright explicitly require) that the PendingIntent you pass in to any of the set() methods should be of the type BroadcastReceiver , but I tested passing in other component types (like an IntentService ) and it seemed to work fine. Is it safe to use non- BroadcastReceiver Intents with AlarmManager ? Yes, and it has always worked, but I suspect not in the way that you're thinking. You can use any PendingIntent with an alarm; this could indeed be an activity or service PendingIntent. If it's a service PendingIntent, then the OS

AsyncTask executed from Service (IntentService) and Activity - is there a difference?

怎甘沉沦 提交于 2019-12-05 18:26:28
Is there any difference between AsyncSync being fired up from Activity or IntentService? I'm building an app which downloads and uploads files via http. I use custom notification layout with progress bar for each transfer. I choose between doing transfers in parallel or putting them into queue (which option would you recommend?). For the option with queue I use an IntentService, so Android framework takes care of putting tasks into a queue for me. For having them in parallel I use AsyncTasks. But I fire them up from IntentService (could be Service as well) - is there any point doing so?

How to check if an IntentService was started

家住魔仙堡 提交于 2019-12-05 17:05:37
I'd like to get to know if an Activity successfully started an IntentService . As it's possible to bind an IntentService via bindService() to keep it running, perhaps an approach would be to check if invoking startService(intent) results in a call of onStartCommand(..) or onHandleIntent(..) in the service object. But how can I check that in the Activity? I'd like to get to know if an Activity successfully started an IntentService. If you don't get an exception in either the activity or the service when you call startService() , then the IntentService was started. As it's possible to bind an

Wait for executed AsyncTask with ProgressDialog

筅森魡賤 提交于 2019-12-05 13:34:12
I have a method public void writeEntry(Activity ctx, Entry entry) which get some data and have to call a native method, which takes longer to finish. So I created an AsyncTask which handles the ProgressDialog and the native method. It works great in an own Activity to test it, in that Activity I used a callback interface and so on. In my case I have the above described method and have to execute the AsyncTask . The executing can't be in that method because it doesn't halt the further execution. I need the result from the native method before I can continue with the execution. Is there any

Stopping an IntentService

▼魔方 西西 提交于 2019-12-05 11:04:37
Does anyone know if there is a way of stopping an IntentService without it finishing its work thread and stopping itself? Simple question, but I couldn't find the answer in the documentation. Is there a simple way of stopping it? Thanks bevor a message to a service is enqueued onStartCommand is called. which forwards the message for queueing. so you could just override onStartCommand, something like that: @Override public int onStartCommand(Intent intent, int flags, int startId) { if (intent.getAction().equals("Stop")) stopSelf(); onStart(intent, startId); return START_NOT_STICKY; } cheers You

IntentService类 和 异步任务(AsyncTask)

£可爱£侵袭症+ 提交于 2019-12-05 08:27:04
IntentService是一个Service类。 IntentService只有1个带String参数的构造方法,所以,在自定义类继承IntentService时,需要在自定义类中显式的调用IntentService带参数的构造方法,并且将自定义类的构造方法修改为无参数的。 IntentService内部使用消息机制,利用消息队列的特性,可以依次处理多个耗时操作。 IntentService具有生命力强、一次性使用、依次处理多个耗时操作的特性。 注意:在自定义类继承IntentService时,可以重写IntentService的生命周期方法,但是,不可以删除super语句 IntentService与ResultReceiver ---------------------------------- ResultReceiver可以实现组件间的通信 【开发流程】 1. 自定义类继承IntentService,显式的定义无参数的构造方法,并注册 2. 在接收结果的类(例如Activity类)中自定义内部类继承ResultReceiver 3. 在需要IntentService执行任务时,使用startService()激活Service组件,并且,将自定义的ResultReceiver对象封装到用于激活IntentService的Intent对象中 4.

loop in IntentService

怎甘沉沦 提交于 2019-12-05 04:44:25
I have an infinite loop in my IntentService to update my view once every 30 seconds based on the input from the main activity. public class IntentServiceTest extends IntentService { String Tag = "IntentServiceTest"; String ACTION_RCV_MESSAGE = "com.jsouptest8.intent.action.MESSAGE"; public IntentServiceTest(){ super("IntentServiceTest"); Log.d(Tag, "IntentServiceTest constructor"); } @Override protected void onHandleIntent(Intent intent) { // TODO Auto-generated method stub Log.d(Tag, "in onHandleIntent"); String url = intent.getStringExtra("URL"); Document doc; int i=0; try{ while(true){ Log

Keeping alive Intent Service after application is killed

孤街浪徒 提交于 2019-12-05 02:41:05
I have intent service in my app. This service has some job to do - uploading some files. It runs only when there is something to do. Service won't upload when some conditions are met, for example no Internet connection. For that reason it registers itself to on broadcast receiver to receive message about Internet connection changes. The problem is that service is killed with app even if it is doing something, for example: App is sending intent to service Service started uploading something, everything fine X% uploaded, app is killed, service is killed Internet connection changed - service is

Async task does not work properly (doInBackground not executing) when service runs in background, Android

≯℡__Kan透↙ 提交于 2019-12-05 02:29:17
I noticed that sometimes Async task does not work properly , Actually its doInBackground() method does not get called , this happens mostly when any service run in background for that activity. For Example , when music runs in background with service, the Async task does not parse XML in background as its doInBackground does not work that time and the progress Dialog or progressBar kept spinning. I read in few articles that AsyncTask.THREAD_POOL_EXECUTOR can help in these issues like : if( Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB ) { new Test().executeOnExecutor(AsyncTask.THREAD