android-service

Is instantiating an AsyncTask from a WakefulBroadcastReceiver recommended?

一曲冷凌霜 提交于 2019-12-30 11:01:42
问题 I can instantiate an AsyncTask from WakefulBroadcastReceiver (see my motivation for favouring AsyncTask over Service), e.g., public abstract class AlarmReceiver extends WakefulBroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { new AsyncTask<Void,Void,Void>(){ @Override protected Void doInBackground(Void... v) { while (true) { SystemClock.sleep(7000); Log.w("", "alive"); } } }.execute(); } } But is this recommendable? In particular, are there life cycle

Android : Stopping a Bonjour service left running after the parent process quit abrubtly

一笑奈何 提交于 2019-12-30 08:49:07
问题 My app is essentially a background service that needs to occasionally register an NSD service ( Bonjour service) for the purpose of enabling discovery of a socket server run by the main background service (aka run by the app). If I am reading the Android Bonjour Service doc correctly, this is how you start the Bonjour service (abbreviated for conciseness): mNsdManager = Context.getSystemService(Context.NSD_SERVICE); mDiscoveryListener = new NsdManager.DiscoveryListener() mNsdManager

Android Service never appears to start - onStartCommand() not called

こ雲淡風輕ζ 提交于 2019-12-30 07:57:23
问题 I am trying to create a service that will handle file I/O in the background. Activities that update the data will bind to the service and call the service's methods to perform the I/O. I am using the Android documentation for guidance. My service does not seem to want to start, however. In the onCreate() method of my Activity, I have: Intent smsIntent = new Intent(this, SurveyManagerService.class); String surveyFilename = getIntent().getStringExtra("surveyFilename"); System.out.println

How to test Doze Mode on Android?

限于喜欢 提交于 2019-12-30 06:37:25
问题 There is an old Android app which work background 2 service (Service). It took to update the app with the possibility of sending data and logging while working is not a new DozeMode. Before you amend the current code I decided to check how everything will work now. To run the application, in the logs I see that both services are running (the basic meaning of the service to read the position of the device, the second service sends the data to the server). Turn off the screen with the command

Getting window display from service android

僤鯓⒐⒋嵵緔 提交于 2019-12-30 06:33:53
问题 I am trying to display a window from service but don't getting it how to do this Here is my code-- In onStart method of Service LayoutInflater inflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE); View view = inflater.inflate(R.layout.main1, null); WindowManager manager = (WindowManager) getSystemService(WINDOW_SERVICE); WindowManager.LayoutParams params = new WindowManager.LayoutParams(); params.type = 2002; params.format = 1; params.flags = 40; params.height = WindowManager

Getting window display from service android

谁说胖子不能爱 提交于 2019-12-30 06:33:27
问题 I am trying to display a window from service but don't getting it how to do this Here is my code-- In onStart method of Service LayoutInflater inflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE); View view = inflater.inflate(R.layout.main1, null); WindowManager manager = (WindowManager) getSystemService(WINDOW_SERVICE); WindowManager.LayoutParams params = new WindowManager.LayoutParams(); params.type = 2002; params.format = 1; params.flags = 40; params.height = WindowManager

Start Android TTS from Broadcast Receiver or Service

二次信任 提交于 2019-12-30 05:30:08
问题 I'm trying to get TTS to run in the background. But, I never get any sound. I have a broadcast receiver which starts a service. I put my TTS code in both of those, but it never speaks. I know the method is being called (I put a breakpoint on it), but it still doesn't work. Here's my log, but it doesn't seem to contain anything about the TTS service. 10-04 22:45:30.663: WARN/InputManagerService(209): Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient

How to Create a android native service and use binder to communicate with it?

此生再无相见时 提交于 2019-12-29 18:02:52
问题 My basic task is to create a native service in android and then write a simple native program to test it. lets say I want to write a simple service which return me sum of two integers. I have to use binders to talk to it from the program, I have tried to google around but I can't find a precise example. I need to know how to create a native service and find it in the program and if needed in Java also. 回答1: If you're creating a normal Android application using the NDK, you can't use Binder

How to Create a android native service and use binder to communicate with it?

可紊 提交于 2019-12-29 18:00:31
问题 My basic task is to create a native service in android and then write a simple native program to test it. lets say I want to write a simple service which return me sum of two integers. I have to use binders to talk to it from the program, I have tried to google around but I can't find a precise example. I need to know how to create a native service and find it in the program and if needed in Java also. 回答1: If you're creating a normal Android application using the NDK, you can't use Binder

Start two services in foreground?

自作多情 提交于 2019-12-29 08:09:15
问题 In an effort to keep my services alive, can I have more than one service in foreground? I am starting two services at once, and I don't want any of them to be destroyed. So, after reading for hours, I found the solution is to return START_STICKY and use startForeground(...) on my service. But, I have two services, so can I have them both be in the foreground, and both never be destroyed? 回答1: There are several aspects to consider. First of all: if you have two services in foreground, you have