android-service

Best practice for pass info from Service to Activity (or Fragment)

不羁的心 提交于 2019-11-30 16:13:48
问题 I am running a Socket.IO client on my Android app and I am having trouble passing data from the Service (that handles the connection of the socket) to one of the Fragments . In one of my Activities , I open up a fragment that has a profile page. When the profile fragment opens, I emit an event to the server asking for the profile information. I am getting the information back from the server with no problems, but I am having trouble sending that data (a JSON string) to the current fragment.

Best practice for pass info from Service to Activity (or Fragment)

一笑奈何 提交于 2019-11-30 16:11:53
I am running a Socket.IO client on my Android app and I am having trouble passing data from the Service (that handles the connection of the socket) to one of the Fragments . In one of my Activities , I open up a fragment that has a profile page. When the profile fragment opens, I emit an event to the server asking for the profile information. I am getting the information back from the server with no problems, but I am having trouble sending that data (a JSON string) to the current fragment. What would be the best practice to pass this information from the Service to the Fragment (or the

service automatically stops after several minutes

六月ゝ 毕业季﹏ 提交于 2019-11-30 16:00:45
问题 I'm creating a service which should work when the activity is in background as well as when the whole application is destroyed. I'm calling location coordinates in the service at every 1 minute interval. However, when I try to do so, the service shuts down automatically just after 12-15 minutes. I want the service to work endlessly until and unless it is destroyed by the completion of activity on user interaction. My service class is as follows: public class SensorService extends Service {

Android Service stops after the app is killed

孤者浪人 提交于 2019-11-30 15:59:10
问题 I want to create a service that runs even when the app is closed from the Task manager. I have created a service and then Logged a message to check if it's running and I noticed that it works only if if the app is running or in foreground. Service class: public class CallService extends Service { private final LocalBinder mBinder = new LocalBinder(); protected Handler handler; public class LocalBinder extends Binder { public CallService getService() { return CallService .this; } } @Override

Android Service stops after the app is killed

ⅰ亾dé卋堺 提交于 2019-11-30 15:48:18
I want to create a service that runs even when the app is closed from the Task manager. I have created a service and then Logged a message to check if it's running and I noticed that it works only if if the app is running or in foreground. Service class: public class CallService extends Service { private final LocalBinder mBinder = new LocalBinder(); protected Handler handler; public class LocalBinder extends Binder { public CallService getService() { return CallService .this; } } @Override public IBinder onBind(Intent intent) { return mBinder; } @Override public void onCreate() { super

Using an Android Service to handle a network connection

こ雲淡風輕ζ 提交于 2019-11-30 15:29:16
I'm working on an Android app that needs to maintain a network connection to a chat server. I understand that I can create a service to initiate the connection to the server, but how would the service notify an Android Activity of new incoming messages? The Activity would need to update the view to show the new messages. I'm pretty new to Android, so any help is appreciated. Thanks! Jordan Can you pass a handler to your service? First, define your handler as an interface. This is an example, so yours may be more complex. public interface ServerResponseHandler { public void success(Message[]

Paho MQTT Android service wake up activity

依然范特西╮ 提交于 2019-11-30 15:15:24
问题 I am trying to use Paho Android MQTT library (downloaded from here). The sample service application works fine, the subscribe and the publish methods work fine too when the sample application is running. When I close it, the device doesn't receive message notifications anymore. Does anyone has an experience how to modify/implement the service correctly to receive message even if the application isn't running? 回答1: You should implement a background service see: http://developer.android.com

Does updating a Notification remove a Service's foreground status?

耗尽温柔 提交于 2019-11-30 14:46:25
问题 In my app, I place my Service in the foreground to prevent it from being killed by using: startForeground(NOTIFY_ID, notification); This also displays the notification to the user (which is great). The problem is that later I need to update the notification. So I use the code: notification.setLatestEventInfo(getApplicationContext(), someString, someOtherString, contentIntent); mNotificationManager.notify(NOTIFY_ID, notification); The question then is: will doing this knock the Service out of

Android service stops when I exit from application

社会主义新天地 提交于 2019-11-30 14:38:02
I have an application with a service. Service is started by app in the main activity on create method. My problem occurs when I exit from application: service stops and sometimes restarts immediately, sometimes restarts lately. I tested in version 4.1.2 and version 2.3.6. service does not again in version 2.3.6. Is my approach wrong? Between the stop and restart times, the call that must blocked can come. Is there any way to not stop the service when app is exited? Note: I cannot use a remote service. i added startForeground to service but the same problem. when i exit application the service

Service not starting on Oreo in app widget using PendingIntent

断了今生、忘了曾经 提交于 2019-11-30 13:44:31
问题 I'm using Android app widgets. I'm creating a PendingIntent object and use it in the method RemoteViews#setOnClickPendingIntent() . This is the pending intent: // The below code is called in the onUpdate(Context, AppWidgetManager, int[]) method of the AppWidgetProvider class. // Explicit intent Intent intent = new Intent(context, MyService.class); intent.setAction(MY_ACTION); intent.putExtra(EXTRA_KEY, VALUE); // Create the pending intent PendingIntent pendingIntent = PendingIntent.getService