intentservice

Static variable in Application class returns null when accessing it

百般思念 提交于 2019-12-10 12:26:44
问题 I am defining a variable in application class like this public static ResultReceiver myResultReceiver = null; In some activities I am extending ResultReceiver and assigning to myResultReceiver, in stop() of activities I am making it null. Though myResultReceiver is not null yet when I access it from an intentservice it is null. The code was working fine till today. 回答1: May be, just may be you have the service on another process using the android:process or android:isolatedProcess attribute.

Wait for executed AsyncTask with ProgressDialog

心不动则不痛 提交于 2019-12-10 08:54:03
问题 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

EnhancedIntentService warning On Incoming Notifications

荒凉一梦 提交于 2019-12-10 04:35:12
问题 I have been getting two errors in my log once a notification is received EnhancedIntentService: Service took too long to process intent: com.google.android.c2dm.intent.RECEIVE App may get closed EnhancedIntentService: binding to the service failed There is NOTHING on Google of either of these messages or even EnhancedIntentService . Relevant code: <service android:name="---.GcmMCIntentService" android:exported="false" > <intent-filter android:priority="10"> <action android:name="com.google

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

这一生的挚爱 提交于 2019-12-10 02:06:44
问题 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(

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

Android service的使用

假装没事ソ 提交于 2019-12-09 18:11:53
Services 一个 Service 是一个应用组件,它可以在后台执行耗时长的操作,而不提供用户接口。另一个应用组件可以启动一个service,然后它将在后台持续运行,即使用户切换到了另一个应用。此外,一个组件可以bind到一个service来与之交互,甚至执行进程间通信(IPC)。比如,一个service可以处理网络事务,播放音乐,执行文件I/O,或者与一个content provider交互,均是在后台。 一个service实质上可以有两种形式: Started 当一个应用组件(比如一个activity)通过调用 startService() 来启动一个service时,则 service 是 "started" 的。一旦被启动,一个service可以在后台无限期地运行,即使启动它的组件已经被销毁了。通常一个被启动的service执行一个单独的操作,并且不给调用者返回一个结果。比如,它可以通过网络下载或上传一个文件。当操作完成时,那个service应该自动停止。 Bound 当一个应用组件通过调用 bindService() 来bind一个service时,则service是 "bound"的。一个bound service提供了一个 允许组件与service交互的 客户端-服务器接口,发送请求,获取结果,甚至通过进程间通信(IPC)来夸进程执行这些。一个bound

Method onHandleIntent() does not get called

懵懂的女人 提交于 2019-12-09 17:48:16
问题 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() {

Android IntentService won't start on boot

◇◆丶佛笑我妖孽 提交于 2019-12-09 07:20:11
问题 I have an IntentService which starts on boot and stays running in the background. There is no launcher Activity, the IntentService is called by a broadcast receiver. It works on 2.3.4 and 4.0.4 devices but not on 4.2.2. Maybe my broadcast receiver isn't being triggered on the device? Manifest: <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="br.com.xxx" android:versionCode="1" android:versionName="1.0"> <uses-sdk android

Waiting for asynchronous callback in Android's IntentService

那年仲夏 提交于 2019-12-09 04:39:32
问题 I have an IntentService that starts an asynchronous task in another class and should then be waiting for the result. The problem is that the IntentService will finish as soon as the onHandleIntent(...) method has finished running, right? That means, normally, the IntentService will immediately shut down after starting the asynchronous task and will not be there anymore to receive the results. public class MyIntentService extends IntentService implements MyCallback { public MyIntentService() {

IntentService, PendingIntent, and AlarmManager: Cannot keep process running indefinitely?

我的未来我决定 提交于 2019-12-08 12:08:22
问题 I've got a pretty simple app that runs two services in the background, using IntentService with AlarmManager. One is a "messaging" service that sends a JSON request and parses the response, the other polls for location from a LocationManager. The requirement here is that they run on an interval, indefinitely, until manually stopped by the user, with a button - even if the device's screen hasn't been turned on for days. The services must never stop. Battery life is not a concern. My minimum