Skip to main content

Posts

Showing posts with the label service

Do I really need a service layer?

My web application is written using Spring MVC + Hibernate. My model is "Customer" entity POJO. I have got a DAO object "CustomerDAO", its method "saveCustomer(c)" contains the code interacting with Hibernate; Then I created a " CustomerService with a "saveCustomer(c)" method who simply pass the customer object to the dao for saving; Finally there are "CustomerController" and customer.jsp, who are responsible for the view layer, the jsp's form fields are bound to a Customer object on the controller side. The controller calls the service.

Android lifecycle weirdness with singleTop and foreground service?

Here's the scenario: Start Activity A Activity A starts service S Service S runs in foreground mode and shows up a notification which when pressed takes the user to Activity B (which has launchMode="singleTop") Activity B shows up Press HOME Go into DDMS and kill your application process to simulate that your app died (press red STOP button) Android will say "Rescheduling crashed service in 5000ms" (sometimes longer) Service S restarts and notification is shown. Press the notification icon when the service restarts... ...at this time, Android will recover both Activities A and B due to the fact the process ended unexpectedly. But despite the fact Activity B is singleTop android will spawn it AGAIN because the user clicked on the notification. This results into having A -> B -> B on the activity stack. Pressing back will take you again onto the first recovered instance of Activity B. Can someone from the Android tea

Catch any touch in the screen in a service

I need a service that know if the user is touching the screen anywhere. If user doesn't touch the screen in a time, I launched a intent to the browser. Someone can help me. I cann´t find the code of how to capture any touch on screen in a service and I cann't think in any solution. Sorry for my English and thanks.

Android : testing a service

we are actually developping an audio service (in the android sense of the term) and we have quite of lot of tests to cover many aspects of our APIs. But we are actually wondering for good things to do to test a service efficiently. So this question is quite open: how would you test an android service ? We are currently using JUnit + EasyMock on test both on real devices and Continous Integration server (via an emulator). Any suggestion is welcome, thx in advance. PS : we have been searching SOF for similar threads but we just found a few cues in those depleted threads : Instrumentation Test case how to bind service from activity Android Service Testing Why is an Android Service not singleton when testing?

Android Activity causing Service crash due to heap fragmentation

I have an Android app (activity) which also has a corresponding service. The service is started by the activity and is supposed to run continuously even when the activity is stopped. When the activity is started again it can bind to the service and query it. Sometimes the activity gets destroyed and created by the OS. This should not affect things, the activity should just be re-created and be able to bind to the service again. This basically works. However... I have found that both the Dalvik VM heap and the native heap are non-compacting and therefore constantly increase in size until the activity runs out of memory and crashes (even though the total memory usage is actually constant and not leaking). This is much exacerbated by destroying and re-creating the activity since a lot of allocations are done during the creation process. This pretty much guarentees that the activity will crash after a number of restarts. This doesn't bother me that much, but what then happens

How to adapt basic android service to run an activity in the background?

I want to create an android service which is able to fetch and parse JSON data into my local database. I have already written the code for this to be done as a normal activity. But I would like to change it so that it updates the database on a regular basis. How would I go about doing this? So far I have created a basic service but I do not know how to tie in my activity into the service or how to set the service to start up when the application is opened up. Basic Data Service public class DataFetcher extends Service { private static final int POLL_PERIOD=120000; private AtomicBoolean active=new AtomicBoolean(true); @Override public void onCreate() { super.onCreate(); } @Override public IBinder onBind(Intent intent) { return(null); } @Override public void onDestroy() { super.onDestroy(); } private Runnable threadBody=new Runnable() { public void run() { while(active.get()) {

How to create an Android Activity and Service that use separate processes

I have an Android app that consists of an activity and a service. Currently they both exist in the same process and use the same heap but I want have to separate process/heap for the service. Ie. I want the service to be completely independent of the activity so that if the activity crashes it won't affect the service. I do, however, want them to be installable as a single application. Is this possible?

Android - Running heavy computations in background and returning the result to an Activity

I have implemented some computationaly heavy functions into my application. Depending on the type of input it can take up to several minutes for a thread to return. During this time, I want the user to be able to work with other activities to perform different tasks (i.e. prepare data for the next run). Then, after the Service has finished it's computations, the user should be notified with a Toast that the result is ready and that he should check back to the Activity he started the Service in. Unfortunately I'm stuck at this point. Is it possible to somehow communicate with an Activity which is destroyed at the moment? Like modifying the saved state, so that when it get's recreated the result will be displayed. The only way of communication I did find was via broadcasting from the Service, but this requires the Activity to listen, which is not possible as it doesn't exist at the moment the Service finishes. The only solution that occured to me was writing a file

ON & OFF Android Broadcastreceiver

Im creating an app in which i do a task when i receive a call (detect RINGING state with a BROADCASTRECEIVER ).My question is that,can I register and unregister (literally;ON and OFF) his broadcastreceiver from an activity having 2 buttons;say one for ON and another for OFF? Does it require the BROADCASTRECEIVER to be declared inside the activity?If I do so,can i register and unregister it,via the activity?