android-service

Android Service is terminated when App destroyed

a 夏天 提交于 2019-12-11 06:57:25
问题 I'm trying to learn Android Service, I'm very noob. I'm creating a service which will run even after the app is destroyed but when I terminate the App, the Service gets terminated too. I'm trying to make a NotificationService, below is my code that I just tried working with Service. Manifest: <service android:name="com.test.testworks.MyService" /> Starting Service via Button Click: startService(new Intent(this, MyService.class)); Service class MyService.class : public class MyService extends

Not sure if service onDestroy is called from BroadcastReceiver

不想你离开。 提交于 2019-12-11 06:49:08
问题 I have a service which I start using Intent serviceIntent = new Intent(getActivity().getApplicationContext(), LocationService.class); getActivity().startService(serviceIntent); When app is going into background, not closed , just not in foreground: i.e. press home button, I do: Notification notification = mBuilder.build(); service.startForeground(NOTIFICATION, notification); To bring the service to the foreground and show ongoing notification. I have a BroadcastReceiver which is fired when

How to keep session in android?

浪子不回头ぞ 提交于 2019-12-11 05:52:08
问题 My app android have connect to webservice (.asmx) use ksoap2. But it has session. When i login service will keep session to manage user - client. But when i login success, session in webservice is keeping null? Can some body tell me why? 回答1: Android is not able to define sessions, as it is a feature of web browsers. The simplest solution we had come up with was to send the sessionID of the web session along with the URL, for e.g.: http://your.required.url/your.context/your.action;jsessionid=

Androidx ServiceTestRule cannot find my service

烂漫一生 提交于 2019-12-11 05:39:31
问题 To be fair, I am not testing the service, but am using a service as part of my test classes to test a Bluetooth library. So my test class needs to create a service that invokes the Bluetooth library. The test class then needs to bind to this service to perform the tests. However, attempting to start the service always gives me the following error which leads to a Nullpointer exception W/ActivityManager: Unable to start service Intent { cmp=com.example.androidhdpadapter.test/com

Using AsyncTask in Service

别来无恙 提交于 2019-12-11 05:36:58
问题 Is that a normal practice of using AsyncTask in Service (not IntentService). Or is it better to create background thread in another way? 回答1: Is that a normal practice of using AsyncTask in Service No. The point of AsyncTask is to be able to do some work on the main application thread after the background work is completed. Services rarely, if ever, need to do work on the main application thread. Or is it better to create background thread in another way? Yes: new Thread() would be a strong

Services stopping automatically from android OS 5.1.1

狂风中的少年 提交于 2019-12-11 05:27:29
问题 I am working on an application related to Voip & IM (chatting application). Till android OS 5.0 it is working good and no issues from client also. But from android OS 5.1.1 onwards we are facing issues. Issues: If the app is in foreground and if device goes to sleep mode it is working good. If the app is in background and if device goes to sleep mode after 10 minutes all the services are stopping automatically . Testing: For testing I created one timer task to print logs for every 1 minute.

How to use Service to update sqlite database in android

左心房为你撑大大i 提交于 2019-12-11 05:15:04
问题 I am able to update sqlite database and retrieving the data through a thread from my Activity. But i need to update the database using Service, which will update the database in every 5 minute, whether my Application running or not. So when i run the application, i will get data from current database. I am stuck while writing Service to update the database.Can someone guide. 回答1: Create a timer object on your service class Timer timer=new Timer(); On on create @Override public void onCreate()

IntentService prevents activity from destroying

…衆ロ難τιáo~ 提交于 2019-12-11 05:09:06
问题 As far as i know, when i rotate the screen, the activity gets destroyed and recreated. In the following scenario, it looks like this is not always the case. So the question is: Is it really destroyed? Am i leaking memory for some reason? If it is not destroyed, does it run on the same thread as the newly created activity? The scenario is an "vertical" Activity that starts an IntentService, the service takes 5 secs to complete, and uses a ResultReceiver to send back the result. During those 5

Run Gps as background service and Compare the received current Location Data with value in Sqlite?

风格不统一 提交于 2019-12-11 04:49:50
问题 I know there are many questions that have been asked regarding this and i have been going through all that from couple of days but couldn't find a reasonable answer.I am newbie to android so i have no idea how things get done. Basically I want to know how to run GPS as a service in background like when the application is installed it starts and how to compare that data received from gps background service with data in SQLite Data Base. 回答1: you can make service like above , this service get

ServiceConnection leak when not using BIND_AUTO_CREATE

不羁的心 提交于 2019-12-11 04:40:06
问题 Could you please explain to me, what happens when we bind to service, but never start it and then unbind? I'm getting "Activity has leaked a Service Connection error", but I do not understand why. MyService: package com.example.servicetest; import android.app.Service; import android.content.Intent; import android.os.Binder; import android.os.IBinder; public class MyService extends Service{ Binder mLocalBinder = new Binder(); @Override public IBinder onBind(Intent intent) { return mLocalBinder