android-service

Launch service from app start, not activity

蓝咒 提交于 2019-12-04 06:05:41
I want to launch a Service when the app is launched instead of an Activity; and then said Service will launch an Activity . I need to do this because my app needs to be running ALWAYS, and when I say ALWAYS I mean ALWAYS. And the only way I've managed to avoid the OS killing my app is by starting a service as Sticky and should Android kill either my Activity or my Service I'll restart them right away. I found this question but the top answer seems rather clumsy, any one has a better idea? PS: I know this doesn't look like a very friendly app but this is a very specific research scenario and it

Can started and bound services live “forever”?

六月ゝ 毕业季﹏ 提交于 2019-12-04 05:50:41
I understand that a service can run in two modes, started and bound. What I don't quite understand from the developer docs or other questions on this site, is whether a service running as both started and bound will exit when the last component unbinds from it? whether a service running as both started and bound will exit when the last component unbinds from it? If something called startService() on the Service , it will remain running, regardless of what bindService() and unbindService() calls may have gone on. Eventually, Android will stop the service, or the user will kill the service, but

How to update an app widget on midnight?

混江龙づ霸主 提交于 2019-12-04 05:38:54
My app has a widget that shows today's date and need to be updated on midnight. The widget is defined in the manifest as <manifest> ... <application> ... <receiver android:name=".MyWidgetProviderClass" android:label="MyLabel" > <intent-filter> <action android:name="android.appwidget.action.APPWIDGET_UPDATE" /> </intent-filter> <meta-data android:name="android.appwidget.provider" android:resource="@xml/widget_icon_info" /> </receiver> </application> </manifest> And the widget info file is <appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android" android:initialLayout="

calling getSystemService inside a service

半腔热情 提交于 2019-12-04 05:13:05
问题 I'm trying to write a service that get the heart rate on Gear Live, following the question here Get Heart Rate from "Sensor" Samsung Gear Live If I put this part Log.d(TAG, "prepare to call getSystemService"); mSensorManager = ((SensorManager)getSystemService(SENSOR_SERVICE)); Log.d(TAG, "after calling getSystemService"); at onCreate() of an activity, it works fine. But if I move that to a Service, it throws a NPE. I tried to add this. in front of `getSystemService, doesn't help. Any tip,

Vibrate on push notification

不打扰是莪最后的温柔 提交于 2019-12-04 04:21:50
First of all I've checked all those links: How to Call Vibrator inside a Service in android Android notifications and vibrate from service Android GCM turn on Lights But I can't achieve my phone vibrating when I receive a push notification. Here goes my code: PushReceiver public class PushReceiver extends FirebaseMessagingService { public PushReceiver() { } @Override public void onMessageReceived(RemoteMessage remoteMessage) { if(remoteMessage.getData() != null){ Map<String, String> data = remoteMessage.getData(); sendNotification(data.get("message")); } else{ if(remoteMessage.getNotification(

emulator cannot start up

我与影子孤独终老i 提交于 2019-12-04 04:21:29
问题 I'm just install HAXM installer and Android SDK Tools and finally my AVD can launch. But the problem is it stucks on the android. I've been waiting for 20 minutes but it still not yet start up.. emulator: device fd:664 HAXM is working and emulator runs in fast virt mode creating window 61 83 462 820 emulator: UpdateCheck: current version '24.4.1', last version '24.4.1' Device Nexus_5_API_23_x86 [emulator-5554] is online, waiting for processes to start up.. Device Nexus_5_API_23_x86 [emulator

ServiceConnection.onServiceConnected() never called after binding to started service

 ̄綄美尐妖づ 提交于 2019-12-04 04:18:59
问题 In a game application I have the following scenario: From the main game Activity , the player starts several game tasks that run in the background with varying duration. The player should be able to view the progress of the running game tasks in a separate View . To do this, I created two Activity s and a Service , defined as follows: Service ProgressService handles several ProgressBar s running simultaneously on parallel threads. Activity WorkScreen2 creates a game task, starts the Service

HotwordDetector using VoiceInteractionService in android

≡放荡痞女 提交于 2019-12-04 04:08:38
I am creating the voice recognition service like "Ok Google" with custom command. For this I have used the VoiceInteractionService and I refered the code from here . Also, I am getting the STATE_HARDWARE_UNAVAILABLE error in onAvailabilityChanged . public class VoiceCommandService extends VoiceInteractionService { private static final String TAG = "AlwaysOnHotwordDetector"; Locale locale = new Locale("en-US"); protected SpeechRecognizer mSpeechRecognizer; protected Intent mSpeechRecognizerIntent; public final Callback mHotwordCallback = new Callback() { @Override public void

Long running service consumes a lot of battery

老子叫甜甜 提交于 2019-12-04 03:47:48
I developed an app and some people complains that it takes too much battery, it is the second most consuming process after the screen. However, in some devices it does not consumes that much battery. All the work my app do is in a service. The service is sticky and is running all the time (the android system may kill it when has low resources or pause it when device go to sleep), it has listener to the accelerometer as long as the screen is on, it is not foreground service and does not hold wakelock. Can someone tell me why it takes a lot of battery? And why is this happening only on some of

How to run service not on main thread?

◇◆丶佛笑我妖孽 提交于 2019-12-04 03:29:40
I'm trying to launch service and then open socket to have connection with server. On button click I create new Thread and then start service. Thread t = new Thread(){ public void run(){ mIntent= new Intent(MainActivity.this, ConnectonService.class); mIntent.putExtra("KEY1", "Value used by the service"); context.startService(mIntent); } }; t.start(); Then on service , I try to open socket and have connection with server @Override public int onStartCommand(Intent intent, int flags, int startId) { //TODO do something useful try { InetAddress serverAddr = InetAddress.getByName(SERVER_IP); socket =