android-service

Pass context to JobService Android JobScheduler

帅比萌擦擦* 提交于 2019-12-10 22:13:30
问题 I am building an app where I store the url and Json in my local SQLite db and then schedule a JobService. In the JobService, I take out all the requests one by one from the db and execute them. Once they are executed, I get the response inside the JobService only. Now my real problem is how do I send the response back to the user from the service. I thought of implementing a callback/listener in activity and passing the value in listener object inside the service. But I am taking out the

Bind service from singleton

社会主义新天地 提交于 2019-12-10 21:57:35
问题 I have a started service that handles a connection and that keep an array of objects. On the other hand, I have a singleton that should bind to that service in order to get one of the objects handled by the service. So, how could I bind the service from the singleton? Is it a good practice to bind the service when the singleton is initialized by using the application's context? Is there a better alternative? Thanks in advance! 回答1: This is a perfectly good way to do it. Your singleton gets

Android Stop Service on Crash

让人想犯罪 __ 提交于 2019-12-10 21:36:04
问题 I am running a Service and am wondering in the rare case that my app crashes will it automatically kill my Service too? I don't want it continuing if this happens. If not, is there a way to do this such as in the onDestroy() method? 回答1: I've done a bit of research, and I think I have a complete answer to your question. Subclassing Service is fine, assuming you're not using a Remote Service (a Service in a different process.) Assuming your Service is in the same process as your Activity ,

Android bound service, what happen when activity unbound it?

拜拜、爱过 提交于 2019-12-10 21:03:39
问题 I have my main activity that can bind a service and call a service method. The service method start a thread (in service) that download data and store them in db. At the end of download the thread can be restarted. What happen if activity call unbindService (i.e. in onPause)? Service is destroyed and thread stopped or the service is destroyed when all task end? 回答1: If the service was previously started using the startService() method and then bound to it, after unbind the service will

Why isn't my local broadcast from a service being received?

左心房为你撑大大i 提交于 2019-12-10 18:49:32
问题 I have an app that includes a service ( WifiDirectFileTransferService ) and a broadcast receiver ( WifiDirectBroadcastReceiver ). The broadcast receiver is used to receive global broadcasts (for WifiP2PManager.WIFI_P2P_..._ACTION ). This part, receiving the global broadcasts, works fine. Then I tried setting up the same broadcast receiver to also receive a local broadcast, for RECEIVED_MESSAGE_DONE_ACTION . Where I was already registering the receiver for global broadcasts in my activity, I

Using an AlarmManager to check periodically that my permanent service is running

╄→尐↘猪︶ㄣ 提交于 2019-12-10 17:52:57
问题 I have a Service which should keep a permanent connection to a server in order to receive notifications. It's critical for my app to get the messages from the server on time. I cannot use GCM Push because the connection will be in the local network and the phone may not have any internet connection. I also know about the battery issues of keeping a permanent connection within a service, but I will let the user choose this option and inform him/her about the potential battery drain (Actually

how to perform widget update by service after clicking a button?

送分小仙女□ 提交于 2019-12-10 17:43:29
问题 This is my Configure activity when I try to deploy the widget initially. public class WeatherAppWidgetConfigure extends PreferenceActivity{ private List<WeatherForecast> weatherData = new ArrayList<WeatherForecast>(); private String city_url; private String city_key; OnSharedPreferenceChangeListener listener; int mAppWidgetId; WeatherForecast wfObj; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Set the result to CANCELED. This will cause

Take a photo with Camera2 using IntentService

六月ゝ 毕业季﹏ 提交于 2019-12-10 17:43:08
问题 I am trying to create an application which takes a photo without showing a preview. Using this tutorial- https://www.youtube.com/watch?v=oPu42I0HSi4 I managed to make it work if I use and Activity . Now I am trying to move the code that handles the picture-taking action into and IntentService . and this is what I got so far: MainActivity.java - Activity private void startCameraService() { if(ActivityCompat.checkSelfPermission(this, Manifest.permission.CAMERA) != PackageManager.PERMISSION

Creating an Android background service that continuously polls a REST API for data

你说的曾经没有我的故事 提交于 2019-12-10 17:28:38
问题 I need to write an Android service that polls a server for data, parses the data, and then sends it to an app via intents. The polling must occur frequently (every few seconds). From what I've read, polling like this is not recommended (due to battery life concerns). This is my first time developing in Android, and after doing a lot of research there are a few things that remain unclear to me. I am unsure if a service, sync adapter, or alarm manager would be better suited for my needs. Which

Android Activity and Service relationship - after Pause, after Stop

笑着哭i 提交于 2019-12-10 16:08:27
问题 Let's say Activity A is created and then A starts a Service S and binds itself to S. S notifies A of updates which will cause the state of A to change. What happens to A and S after Android pauses or stops A? For instance: Does pausing A automatically unbind it from S (thus stopping S if A is the last thing bound to it?) Do updates from S cause A to be resumed? Do updates from S never get passed to A and no error occurs? Can S become aware that A is paused or stopped? (for instance by a call