intentservice

Android InstantiationException : No empty constructor

孤人 提交于 2019-11-29 12:45:01
I get an InstantiationException when I try to start an IntentService. I have looked at other threads here but the answers don't solve my problem. My service class does have a default constructor. Here's my service class. (It is defined in a file FindMeService.java and that's the only class in that file.) package com.findme.findme; import android.app.IntentService; import android.content.Intent; import android.os.Bundle; import android.support.v4.content.LocalBroadcastManager; public class FindMeService extends IntentService { /*public static class Constants { }*/ public static final String

Design pattern for alternate action if app in foreground?

僤鯓⒐⒋嵵緔 提交于 2019-11-29 11:29:20
I'm building an action which utilizes Google Cloud Messaging for receiving push notifications. This involves a couple notable components, namely: A WakefulBroadcastReceiver to receive the message from GCM. An IntentService to be notified when a GCM event is received. As I'm sure is the case for many applications, I'd like to take a different approach for when the application has an activity in the foreground vs. when the application does not have an application in the foreground. I'd like to post a notification to the notification drawer if the application is not active, and simply forward the

WakefulIntentService implementation clarifications

人走茶凉 提交于 2019-11-29 11:11:01
Commonsware's WakefulIntentService works beautifully but there are some things I do not quite get. Below is the core of the service - a stripped down version of the source : class WIS extends IntentService { private static final String NAME = WIS.class.getName() + ".Lock"; private static volatile WakeLock lockStatic = null; synchronized private static PowerManager.WakeLock getLock(Context context) { if (lockStatic == null) { PowerManager mgr = (PowerManager) context .getSystemService(Context.POWER_SERVICE); lockStatic = mgr.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, NAME); lockStatic

How do I keep the Thread of an IntentService alive?

自闭症网瘾萝莉.ら 提交于 2019-11-29 11:05:58
I'm writing a test application which keeps track of the users location. The idea is that i can start a service which then registers for location updates. For now I'm using an IntentService for that. The service code (which is not working...) looks like that: public class GpsGatheringService extends IntentService { // vars private static final String TAG = "GpsGatheringService"; private boolean stopThread; // constructors public GpsGatheringService() { super("GpsGatheringServiceThread"); stopThread = false; } // methods @Override public int onStartCommand(Intent intent, int flags, int startId)

Is there any reason to continue using IntentService for handling GCM messages?

五迷三道 提交于 2019-11-29 10:24:35
As you know, recently Google changed their GCM documentation, and they claim that an IntentService is no longer required for handling arriving GCM messages. All the handling can be done in the BroadcastReceiver . When trying to figure out if there is any good reason to continue using the IntentService , I came across this quote : A Service (typically an IntentService) to which the WakefulBroadcastReceiver passes off the work of handling the GCM message, while ensuring that the device does not go back to sleep in the process. Including an IntentService is optional —you could choose to process

Failed to resolve Intent Service Android

霸气de小男生 提交于 2019-11-29 04:49:46
I am getting following error when trying to configure Push Notification: 06-07 01:05:59.735 18708-18708/com.ebr.apps.ebr.development E/FirebaseInstanceId: Failed to resolve target intent service, skipping classname enforcement 06-07 01:05:59.735 18708-18708/com.ebr.apps.ebr.development E/FirebaseInstanceId: Error while delivering the message: ServiceIntent not found. I have different flavors in gradle: My code package name is : com.ebr.apps.ebr My product flavor package is: com.ebr.apps.ebr.development I have placed google-services.json in app/src/development Manifest: <permission android:name

When to unregister BroadcastReceiver? In onPause(), onDestroy(), or onStop()?

不想你离开。 提交于 2019-11-28 21:08:33
When should I use unregisterReceiver? In onPause() , onDestroy() , or onStop() ? Note: I need the service to run in the background. Update: I get an exception releasing receivers null . Activity has leaked intent receivers are you missing call to unregisterReceiver(); Please tell me if there's something wrong, here's my code: private boolean processedObstacleReceiverStarted; private boolean mainNotificationReceiverStarted; protected void onResume() { super.onResume(); try { registerReceivers(); } catch (Exception e) { Log.e(MatabbatManager.TAG, "MAINActivity: could not register receiver for

第11章 Android的线程和线程池

落花浮王杯 提交于 2019-11-28 19:45:37
除了Thread以外,在Android中可以扮演线程的角色还有很多,比如AsyncTask和IntentService,同时HandlerThread也是一种特殊的线程。 AsyncTask封装了线程池和Handler。HandlerThread是一种具有消息循环的线程,在它的内部可以使用Handler。IntentService是一个服务,IntentService内部采用HandlerThread来执行任务,当任务执行完毕后IntentService会自动退出。IntentService是一种服务,不容易被系统杀死从而可以尽量保证任务的执行,如果是一个后台线程,由于这个时候进程中没有活动的四大组件,那么这个进程的优先级就会降低,容易被系统杀死,这就是IntentService的优点。 11.1 主线程和子线程 从Android3.0开始系统要求网络访问必须在子线程执行,否则网络访问将会失败并抛出NetworkOnMainThreadException这个异常。 11.2 Android中的线程形态 11.2.1 AsyncTask AsyncTask是一种轻量级的异步任务类,它可以在线程池中执行后台任务,然后把执行的进度和最终结果传递给主线程并在主线程中更新UI。 4个核心方法: onPreExecute() doInBackground(Params… params

How to Collect info from IntentService and Update Android UI

∥☆過路亽.° 提交于 2019-11-28 18:57:52
I'm learning Android and I'm stuck with my service. My application connects via Socket to my server every X seconds, receives an XML, parses the information and it's shows in a TextView. I'd like to know how can I implement an IntenService to do this and how to communicate the info to the UI. I'm finding very hard to see good examples. I appreciate any help you can give me. Thank you! Farhan Use a handler and send a message to parent activity from the intentservice Parent Activity : Declaring Handler Handler handler = new Handler() { @Override public void handleMessage(Message msg) { Bundle

Should I use AsyncTask or IntentService for my application?

风格不统一 提交于 2019-11-28 16:38:47
I have been reading around on internet connectivity with Android and noticed there are different ways to handle this i.e. AsyncTask and IntentService . However, I'm still not sure which one to use. My application is basically a location/trails finder with Google Maps. My internet connectivity will be used to find the nearest trails within a certain radius of the map. So, every time a user moves or swipes the map to a new location then it will update with the nearest trails. It will also add a new trail, and allow the user to rate a trail. Will AsyncTask suffice for this or should I use