service interview questions
Top service frequently asked interview questions
How do you automatically start a service after running an install from a Visual Studio Setup Project?
I just figured this one out and thought I would share the answer for the general good. Answer to follow. I am open to other and better ways of doing this.
Source: (StackOverflow)
what are the differences between .aspx and .ashx pages.
I use ashx now when I need to handle a request that called from code and return with a response. but I still want more technical answers please.
Source: (StackOverflow)
I'm building a site that relies quite heavily on a third party API so I thought it would make sense to package up the API wrapper as a service, however I'm starting to find instances where it would be useful to have access to it outside of a controller such as in an entity repository.
Also related to that is it would be useful to be able to get access to config values outside of a controller (again such as in an entity repository).
Can anyone tell me if this is possible and if not is there a suggested approach to doing this kind of thing?
thanks for any help
Source: (StackOverflow)
I'm developing an app on Android OS. I don't know how to check if Location Services are enabled or not.
I need a method that returns "true" if they are enabled and "false" if not (so in the last case I can show a dialog to enable them).
Source: (StackOverflow)
I've been trying to start a service when a device boots up on android, but I cannot get it to work. I've looked at a number of links online but none of the code works. Am I forgetting something?
AndroidManifest.xml
<receiver
android:name=".StartServiceAtBootReceiver"
android:enabled="true"
android:exported="false"
android:label="StartServiceAtBootReceiver" >
<intent-filter>
<action android:name="android.intent.action._BOOT_COMPLETED" />
</intent-filter>
</receiver>
<service
android:name="com.test.RunService"
android:enabled="true" />
BroadcastReceiver
public void onReceive(Context context, Intent intent) {
if ("android.intent.action.BOOT_COMPLETED".equals(intent.getAction())) {
Intent serviceLauncher = new Intent(context, RunService.class);
context.startService(serviceLauncher);
Log.v("TEST", "Service loaded at start");
}
}
Thanks
Source: (StackOverflow)
I have a service class. I have exported this class to jar and I have embed the jar in my client app.
When needed, I call the service class. When I try to do this, I get the following error:
Unable to start service Intent {comp={com.sample.service/com.sample.service.serviceClass}} : not found
I have other class apart from the service class, which I am able to access (create object of that class) which are inside the same jar.
I feel I have missed out some thing in my configuration or manifest or so.
Please help me identifying the same. My code is below:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent intent = new Intent () ;
intent.setClassName("com.sample.service" ,"com.sample.service.serviceClass") ;
this.startService(intent) ; // when I call this line I get the message...
// binding other process continue here
}
Client manifest.xml
<service android:name="com.sample.service.serviceClass"
android:exported="true" android:label="@string/app_name"
android:process=":remote">
<intent-filter><action android:name="com.sample.service.serviceClass"></action>
</intent-filter>
</service>
Thanks in advance,
Vinay
Source: (StackOverflow)
I am trying some thing new on Android for which I need to access the handler of the UI thread.
I know the following:
- The UI thread has its own handler
and looper
- Any message will be put
into the message queue of the UI
thread
- The looper picks up the event
and passed it to the handler
- The handler handles the message and
sends the specfic event to the UI
I want to have my service which has to get the UI thread handler and put a message into this handler.
So that this message will be processed and will be issued to the UI.
Here the service will be a normal service which will be started by some application.
I would like to know if this is possible.
If so please suggest some code snippets, so that I can try it.
Regards
Girish
Source: (StackOverflow)
Hallo,
I'm trying to let a python script run as service (daemon) on (ubuntu) linux.
On the web there exist several solutions like:
http://pypi.python.org/pypi/python-daemon/
A well-behaved Unix daemon process is tricky to get right, but the required steps are much the same for every daemon program. A DaemonContext instance holds the behaviour and configured process environment for the program; use the instance as a context manager to enter a daemon state.
http://www.jejik.com/articles/2007/02/a_simple_unix_linux_daemon_in_python/
However as I want to integrate my python script specifically with ubuntu linux my solution is a combination with an init.d script
#!/bin/bash
WORK_DIR="/var/lib/foo"
DAEMON="/usr/bin/python"
ARGS="/opt/foo/linux_service.py"
PIDFILE="/var/run/foo.pid"
USER="foo"
case "$1" in
start)
echo "Starting server"
mkdir -p "$WORK_DIR"
/sbin/start-stop-daemon --start --pidfile $PIDFILE \
--user $USER --group $USER \
-b --make-pidfile \
--chuid $USER \
--exec $DAEMON $ARGS
;;
stop)
echo "Stopping server"
/sbin/start-stop-daemon --stop --pidfile $PIDFILE --verbose
;;
*)
echo "Usage: /etc/init.d/$USER {start|stop}"
exit 1
;;
esac
exit 0
and in python:
import signal
import time
import multiprocessing
stop_event = multiprocessing.Event()
def stop(signum, frame):
stop_event.set()
signal.signal(signal.SIGTERM, stop)
if __name__ == '__main__':
while not stop_event.is_set():
time.sleep(3)
My question now is if this approach is correct. Do I have to handle any additional signals? Will it be a "well-behaved Unix daemon process"?
Source: (StackOverflow)
I'm wondering how apps like SwipePad and Wave Launcher are able to detect touch gestures/events simply through a service. These apps are able to detect a touch gestures even though it is not in their own Activity. I've looked all over the Internet and haven't found how they can do that.
My main question is how a service can listen in on touch guestures/events just as a regular Activity may receive MotionEvents even though it may not be in the original Activity or context. I'm essentially trying a build an app that will recongize a particular touch gesture from a user regardless which Activity is on top and do something when that gesture is recongized. The touch recongition will be a thread running in the background as a service.
Source: (StackOverflow)
I am developing an application which will be able to record video from background of application by using Service
.
Problem description :
In my application recording will be scheduled. If user want to record video from 1 PM to 3 PM, he will schedule the task and can exit from application. Application will automatically start recording at 1PM to 3PM.
What I did yet :
I googled about my query but didn't get solution. Many articles say that it is not possible. But in Google Play there are some applications (for eg MyCar Recorder) which can record video from background of application.
I got an article about same but its not working.
What is the way to implement this functionality?
Source: (StackOverflow)
I have a foreground service setup in Android. I would like to update the notification text. I am creating the service as shown below.
How can I update the notification text that is setup within this foreground service? What is the best practise for updating the notification? Any sample code would be appreciated.
public class NotificationService extends Service {
private static final int ONGOING_NOTIFICATION = 1;
private Notification notification;
@Override
public void onCreate() {
super.onCreate();
this.notification = new Notification(R.drawable.statusbar, getText(R.string.app_name), System.currentTimeMillis());
Intent notificationIntent = new Intent(this, AbList.class);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
this.notification.setLatestEventInfo(this, getText(R.string.app_name), "Update This Text", pendingIntent);
startForeground(ONGOING_NOTIFICATION, this.notification);
}
I am creating the service in my main activity as shown below:
// Start Notification Service
Intent serviceIntent = new Intent(this, NotificationService.class);
startService(serviceIntent);
Source: (StackOverflow)
I am creating a application whose only component is a service which keeps on running in background (basically a proxy server) but I am not able to find a way how to start that service. Application can not have any UI or user interaction so I am not using Activity.
Broadcast receiver can listen to BOOT broadcast but how do I start service first time when it is installed and how can I keep it running?
or is there a broadcast which I can listen after app is installed e.g. may be TIME_TICK but that has to be registered from activity i think
Source: (StackOverflow)
I'm trying to convert an Angular HTTP.get
function in my controllers.js
to a service in services.js
.
The examples I have found all have conflicting ways to implement the service and their choice of names is confusing. Furthermore, the actual angular documentation for services uses yet a different syntax than all the examples. I know this is super simple, but please help me out here.
I have app.js
, controllers.js
, services.js
, filters.js
.
app.js
angular.module('MyApp', []).
config(['$routeProvider', function($routeProvider)
{
$routeProvider.
when('/bookslist', {templateUrl: 'partials/bookslist.html', controller: BooksListCtrl}).
otherwise({redirectTo: '/bookslist'});
}
]);
controllers.js
function BooksListCtrl($scope,$http) {
$http.get('books.php?action=query').success(function(data) {
$scope.books = data;
});
$scope.orderProp = 'author';
}
Source: (StackOverflow)
I have written a Java server application that runs on a standard virtual hosted Linux solution. The application runs all the time listening for socket connections and creating new handlers for them. It is a server side implementation to a client-server application.
The way I start it is by including it in the start up rc.local script of the server. However once started I do not know how to access it to stop it and if I want to install an update, so I have to restart the server in order to restart the application.
On a windows PC, for this type of application I might create a windows service and then I can stop and start it as I want. Is there anything like that on a Linux box so that if I start this application I can stop it and restart it without doing a complete restart of the server.
My application is called WebServer.exe. It is started on server startup by including it in my rc.local as such:
java -jar /var/www/vhosts/myweb.com/phpserv/WebServer.jar &
I am a bit of a noob at Linux so any example would be appreciated with any posts. However I do have SSH, and full FTP access to the box to install any updates as well as access to a Plesk panel.
Source: (StackOverflow)
Angular clearly states in its documentation that Services are Singletons:
Angular services are singletons
Counterintuitively, module.factory
also returns a Singleton instance.
Given that there are plenty of use-cases for non-singleton services, what is the best way to implement the factory method to return instances of a Service, so that each time an ExampleService
dependency is declared, it is satisfied by a different instance of ExampleService
?
Source: (StackOverflow)