android-service

calling onCreate from different threads at the same time

陌路散爱 提交于 2019-12-04 19:07:16
I have read Android documentation in which a piece of code is synchronized inside the onCreate method, Sync Adapter . AFAIK Android only creates one instance of a Service so, can Android call onCreate from different threads at the same time? or is it possible to call a Service method before onCreate has finished (using AIDL)? The documentation you linked to (regarding creating SyncAdapter in a thread-safe manner) makes no sense. onCreate() of a Service is only ever called on the main thread, so there is no possibility that this isn't thread-safe. Also, you cannot call any methods using AIDL

get last Call on CallLog using a Service

血红的双手。 提交于 2019-12-04 18:24:23
I'm doing a program to send the CallLog to a Server, I created a Service that makes a poll of the telephone status with the following method. This method is called onCreate. private void pollForCallStatus() { timer.scheduleAtFixedRate(new TimerTask() { @Override public void run() { Log.d("Poll", Integer.toString(telephonyManager.getCallState())); switch (telephonyManager.getCallState()){ case TelephonyManager.CALL_STATE_RINGING: Log.d("CallService", "ringing"); break; case TelephonyManager.CALL_STATE_OFFHOOK: callStart(); break; case TelephonyManager.CALL_STATE_IDLE: callEnd(); break; } } }, 0

Implementing a thread pool inside a Service

故事扮演 提交于 2019-12-04 18:05:28
问题 I'm currently working on implementing a Service that when requested will perform some work on several parallel threads. My implementation is based on the ThreadPoolExecutor class along with a LinkedBlockingQueue . As a ground rule, once all tasks are finished and the are no pending tasks in the queue, I would like to stop the service (though the service can later on be started again and follow the same logic). I have been able to reach the desired outcome using the code below, yet I'm not

foreground service without notification

一曲冷凌霜 提交于 2019-12-04 16:55:27
I want to start a foreground service that doesn't show notification, apps like instagram, telegram, zapya, ... have a foreground service and they show no notifications. I have tested ways like answers here , but android shows a notification that yourAppName is running . I want to know how is that possible to have a foreground service with no notification or warning from OS? Sam How to do it Here's an up-to-date technique to make it work on all Android versions: When the app is running on an Android version prior to 7.1, use this technique . When the app is running on Android 7.1 or higher, use

Retriving image from server to android app

一个人想着一个人 提交于 2019-12-04 15:43:28
问题 package com.sample.downloadImage; import java.io.BufferedInputStream; import java.io.IOException; import java.io.InputStream; import java.net.HttpURLConnection; import java.net.URL; import java.net.URLConnection; import org.apache.http.util.ByteArrayBuffer; import android.app.Activity; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.os.Bundle; import android.widget.ImageView; public class downloadImage extends Activity { @Override public void onCreate

How to pass value from Activity to a Service in Android?

旧时模样 提交于 2019-12-04 15:37:41
问题 I need access a simple int variable which holds an editText element value. The value is stored as a public field on my Activity class. On my Service, I created an object from my activity class: CheckActivity check = new CheckActivity(); and I am trying to access it by: check.getFirstPosition(); but it returns zero. What should I do to pass the value from an Activity to a Service? 回答1: You cannot create an object like that from your service. I think you are new to Java. When you do

Android foreground service slow if device is idle

╄→尐↘猪︶ㄣ 提交于 2019-12-04 14:13:19
问题 I have an android foreground service, called with the notification. In the service Im just logging every 10 seconds "Tick tack", but the priority of the service is navigate in a webview every X seconds, so Im using new threads and working in the main thread too. If I have the app connected to the usb the logs seems ok, the "tick tack" is called every 10 seconds, same if the mobile is unlocked and Im wathing the logs on the app. But when I disconnect the usb, or I lock the device this is what

Creating a notification for MediaPlayer with an Android Foreground Service

半城伤御伤魂 提交于 2019-12-04 14:12:02
Here is the problem. I am currently working on an application that must provide : A Radio Player (AAC live streaming from an url) And a PodCast player (MP3 Streaming from an url) The application must be able to run in background (Android Service) and be exposed to the user with a persistant notification in the Notification Bar (Android Foreground Service) (ONE problem per question so here i'll be asking for the notification) Since i have several class for managing players, i though creating a generic class for the noticication would be a good idea. Here is the kind of view i would like to

Android: get reference to started Service in instrumentation test

岁酱吖の 提交于 2019-12-04 13:37:01
I'm trying to write instrumentation test for my NetworkMonitorService as described in the official " testing your service " documentation. Currently I'm stuck because I can't figure out how can I grab a reference to the started service in order to inject mocks into it and assert behavior. My code: @RunWith(AndroidJUnit4.class) @SmallTest public class NetworkMonitorServiceTest { @Rule public final ServiceTestRule mServiceTestRule = new ServiceTestRule(); @Test public void serviceStarted_someEventHappenedInOnStartCommand() { try { mServiceTestRule.startService(new Intent( InstrumentationRegistry

Starting LocationManager as Service Android

空扰寡人 提交于 2019-12-04 13:19:00
问题 What I'm attempting to do is when receiving a c2dm message, start a service that asks for location for 'x' amount of time and then hands that location off to our server. The c2dm message starts the service correctly, and the GPS location turns on, but it never updates. It just sits there for the length of time I specify (currently 12 seconds) in the thread and does nothing. I'm using the exact same code somewhere else in my app (not as a service) and it works perfectly. What am I doing wrong?