android-service

Send data from activity to running service

老子叫甜甜 提交于 2019-12-04 09:05:33
I have a short question. How can I send data from an activity to an already running service? The approach is as following, I have a service running in the background, which is starting a new activity that is just showing an input window. And now I want to send the typed data back to the service. How can this be done? Thanks in advance for helping! Best regards Tobi Are you aware of onBind method of Service class? 来源: https://stackoverflow.com/questions/6225157/send-data-from-activity-to-running-service

Widget setOnClickPendingIntent not starting service

社会主义新天地 提交于 2019-12-04 09:02:09
Following the example here i created my widget with ease. I then added a button to my widget, this button should start a service so I added the following code to my WidgetProvider @Override public void onEnabled(Context context) { Log.e("ERROR", "REMOVE ME"); // TODO remove. This is for eclipse logcat recognition RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget_layout); Intent intent = new Intent(context, RepairService.class); PendingIntent pi = PendingIntent.getService(context, 0, intent, 0); views.setOnClickPendingIntent(R.id.widget_boost, pi); } The code

Can't receive LocationClient's location updates after screen gone off

本秂侑毒 提交于 2019-12-04 08:05:34
I'm trying to write a simple Android Service that runs in background and receives location updates from LocationClient (Google Map API Android V2). The problem is that when the screen go off, my Service doesn't receives anymore location updates. I tried to check if the service was active, even with screen off, and it does (I have a TimerTask scheduling a log). When screen is on I can receive location updates, but when screen goes off I see only TimerTask's logs and I don't receive any location update. Waking up screen turns on location updates again. How can this be solved? Here is my simple

What is the preferred way to call an Android Activity back from a Service thread

淺唱寂寞╮ 提交于 2019-12-04 08:02:00
I'm currently developing an Android application that has the following needs: A worker thread started in a Service. This thread does some processing and needs to be invoked from the main Activity and provide some asynchronous answers to the same Activity. Invoking the Service from the Activity is easy (IBinder stuff) My question is now about the proper implementation of the service callback. I was first going to add an android.os.Handler in the Activity and handle the thread's anwers in MyActivity.handleMessage(Message) but this requires that I give this handler's reference to the service. So

Android : Do Application Login in background on boot-up

北战南征 提交于 2019-12-04 08:00:59
I have a VOIP Application, I need to login the application in background on device bootup. Currently the init to my application is done on UI Active( onCreate() ). I have the following things in my mind, can anyone help and clear my doubts. The service design is must to achieve this task?? Which Service Remote(AIDL) or Local Service and why? How does the UI and Service interaction happens? After UI is active who gets the Call- Backs? UI or Service ? Should i make Service as my Controller i.e Service to UI data Pass Vice-versa? Sample App: Skype. So there are many ways to achieve what you want,

Why unbind Service onDestroy?

纵饮孤独 提交于 2019-12-04 07:54:00
I've seen it mentioned in multiple sources, that if an Activity binds a Service, it should unbind it onDestroy. Why? Since the Activity is destroyed, it seems like the service will be unbound anyway. If it was "started" - it doesn't matter anyway. And if it was auto-started by the activity - it will close anyway if no others bound it. So why unbind it? Activities need to handle configuration changes, such as when the screen is rotated, or the user changes locales, or the device enters night mode. The default behavior of the foreground activity, when a configuration change occurs, is for it to

A foreground service gets killed and notification gets removed when app is swiped from recent apps

痴心易碎 提交于 2019-12-04 06:35:06
I have a foreground-service with notification. When the app is swiped away from recent apps tray, service gets killed and notification also gets removed. Here is the code for my service VoiceService.class : @Override public IBinder onBind(Intent intent) { return null; } @Override public int onStartCommand(Intent intent, int flags, int startId) { showNotification(); Toast.makeText(this, "Service Started!", Toast.LENGTH_SHORT).show(); return START_STICKY; } private void showNotification() { new SetupTask(this).execute(); // a method in my code which works fine. Intent notificationIntent = new

Android calling IntentService class from a Service Class

旧巷老猫 提交于 2019-12-04 06:32:32
问题 Can we call IntentService class from a running Service class . Intent myintentservice = new Intent(this, MyIntentService.class); startService(myintentservice); I using above lines of code in service class to start IntentService class. But then I get following error:- Process: objectdistance.ankeshkjaisansaria.ram.sita.cameratag, PID: 21823 java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String android.content.Context.getPackageName()' on a null object reference at

Method onHandleIntent() does not get called

主宰稳场 提交于 2019-12-04 06:29:25
After many hours of researching I am finally consulting official help. Why does not onHandleIntent() get called? Is there something wrong here? In main activity onCreate() : mService = new Intent(context, xyz.class); startService(mService); That iss it. The onStartCommand() gets called, but not onHandleIntent() package com.autoalbumwallaperplus; import android.app.IntentService; import android.content.Intent; import android.widget.Toast; public class xyz extends IntentService { public xyz() { super("bmp"); } @Override public int onStartCommand(Intent intent, int flags, int startId) { Toast

Using TYPE_STEP_COUNTER in a background service?

耗尽温柔 提交于 2019-12-04 06:12:25
I'm looking at implementing the step sensor API introduced in Android 4.4 ( http://youtu.be/yv9jskPvLUc ). However, I am unable to find a clear explanation on what the recommended way to monitor this in the background is? It seems like most examples only show how to do this with an activity while the app is running. I don't particularly need a high frequency of updates - I basically want to log the amount of steps the user has walked every hour to a backend service. Should I just spin up a background service that calls registerListener on SensorManager, or is there a more elegant way? As far