Android :: Remote Service Destroyed When Main Activity Closed / How To Fix?
Nov 19, 2010
I wrote an android program that: has a main activity for UI, and it starts a service. The service timely callbacks the UI activity to update views. It works fine except: if the activity is closed (with BACK) and start again, the service will also be started again (The service plays audio file, so there are two overlapped sounds). I use bindService with BIND_AUTO_CREATE flag to start and connect to service. According to the document, it should create service only if it doesn't exist, but obviously it starts another instance when opened second time. All I want is when the activity is closed, the service goes on running, and when the activity opens again, it can reconnect to the service. Is that possible? Or I just misunderstand the usage of service?
View 1 Replies
Nov 9, 2010
I need to develop an application with downloads the data at the background and update about the progress in the front.
I guess this can be achieved using services and activity and passing data in between the. But, what I need to do is even if I hit back button and then start the activity again. It should check if the service is running or not. If service is not running it should start one else it should display the data from running service.
Something like music player where music is played by a service at a background and activity displays the information. Even on browsing through other activities of the application or hitting back, state of the music player is maintained.
View 1 Replies
View Related
Nov 23, 2010
If I understand it correctly, bindService() with BIND_AUTO_CREATE will start a service and will not die until all bindings are all unbinded.
But if I bindService(BIND_AUTO_CREATE) at onCreate() and hit back button to close the activity, the service calls onDestroy() and dies also.
I don't call unbind() at anytime. So is that mean when the Activity got destroyed, the binding got destroyed also and the service gets destroyed also?
What if I want the service to be always running, at the same time when the activity starts I want to bind it so that I can access the service?
If I call StartService() and then bindService() at onCreate(), it will restart the service at every launch of Activity. (Which I don't want).
So I could I start service once and then bind next time I launch the activity?
View 1 Replies
View Related
Aug 24, 2010
I have a service which collect data and send them to a certain URL and updating the main activity GUI, so which is better in the performance to use a long service with listeners to collect the data and threads in it to update the GUI and sends to the internet or to make another service responsible for updating the GUI and sending to the URL only while the first one just collects the data?
View 5 Replies
View Related
Nov 11, 2010
so the application I've written has a service (that tracks GPS data) with a single main activity that binds to it with bindService in it's onStart() method, and unbinds from the service in it's onStop() method using unbindService( ServiceConnection ). I also have an activity which is an options screen, that is launched by pressing a button on the main activity. On this options screen, I have a checkbox that says "Run in background", which, if set to true, means that when the user exits the application with eier the Home or Back buttons, the service will continue running, not turning the GPS off. I do this by calling this.startForeground onUnbind, and this.stopForeground onRebind, if the setting is set to true, and stopping and starting my location reader onUnbind and onRebind respectively if the setting is false. If the service is running in the background, it also displays a notification to ensure the user understands that the GPS is still running and draining their power. This notification is displayed and stopped by relying on the startForeground and stopForeground methods......
View 1 Replies
View Related
Oct 30, 2010
In my application, there is a service which has a running thread to capture data from remote server, and also this service is triggered by AlarmManager, for example let 1:00 am to start the service. After the service finish the task, it stop itself and the main activity need to update GUI. I don't know how to let the main activity know when the the service stopped, so that the main thread can update GUI.
View 3 Replies
View Related
Oct 8, 2010
My initial activity is basically a splash screen while preforming initialization and login in to network server. To save memory I want to finish() the splash activity once it starts the main menu activity. I still want the remote service to operate. Testing shows it does. But am I going to get into trouble doing this? I know I can restart the remote from the main menu activity but I am trying to save overhead by not starting it twice. The remote service is required by the splash activity.
View 1 Replies
View Related
Nov 23, 2009
I am binding a remote service from an activity and unbind the same on the onPause of the Activity,when the activity again restarts i bind the service .It does bind with the remote service and i am also successful in getting the remote-service method getting executed after the restart.But when returning a message from the callback-RemoteCallbackList.the mCallbacks.beginBroadcast returns me 0 clients.Am i missing some thing here ?why am i am getting zero clients when I call mCallbacks.beginBroadcast.?
CODE:....................
View 2 Replies
View Related
Apr 29, 2010
Iam trying to run an activity from diffrent package from my remote service:
This is how i implement the service.java
CODE:....
Ive also added a line in the manifest of the service:
The service works fine, but i cant run the activity -> PushActivity which is in diffrent package of diffrent application, this is the error:
Activity not found Exception: No Activity found to handle Intent {act=com.pushservice.PushServiceActivity flq=0x10
View 2 Replies
View Related
Mar 30, 2009
How do you pass an intent from a service to a new activity launched from a main activity? There's a passextra( intent src ); but I don't think thats what I am looking for?
activity main > start service( intent wuteverserviceintent );
activity main > start activity( intent newactivityintent );
View 2 Replies
View Related
May 3, 2010
I have a widget that is supposed to start and stop a service (start it when it's not running, stop it when it is). This is working fine, however, each time the service is started, my app's main activity is also launched, which I don't want from the app's manifest, it works as I want it to (without launching the main-activity, just the service), but then I obviously don't have a main activity anymore.This is how I start the service (I would assume this is the normal way, and I can't see any reference to what might cause the MAIN intent to fire).
View 1 Replies
View Related
May 2, 2010
I've configured local service under some app i wanna know how could i invoke methods on the activity, through the service in a synchronous way for example the service invoke a method inthe activity and waiting for for result(synchronous) from it.
View 2 Replies
View Related
Nov 24, 2010
In onCreate method of Activity, it binds to a remote service and makes use of AIDL intefaces. Is it required to unbind from the remote service when onDestroy is called on screen orientation change.?
If the activity un-bounded from the remote service in onDestroy and if no other contexts are bound to remote service, is remote service likely to get stopped losing the state that it maintains.?
View 1 Replies
View Related
Mar 27, 2010
I have an AsyncTask object which starts executing when the activity is created and does stuff in the background (downloads upto 100 images). Everything works fine but there is this peculiar behavior which i'm not able to understand.For eg: when the android screen's orientation changes then the activity is destroyed and created again. So I override the onRetainNonConfigurationInstance() method and save all the downloaded data executed in the AsyncTask. My purpose of doing this is to not have AsyncTask run each time activity is destroyed-created during orientation changes, but as i can see in my logs the previous AsynTask is still executing. (The data is saved correctly though)I even tried to cancel the AsynTask in the onDestroy() method of the activity but the logs still show AsynTask as running.This is really strange behavior and would really be thankful if someone can tell me the correct procedure to stop/cancel the AsynTask.
View 1 Replies
View Related
Sep 24, 2009
I press program's icon to start my program,and then open the Settings activity through startActivityForResult(intent, SETTINGS). Now i press the home key and start my program through program's icon, at this time the Settings actitity will run OnDestroy() and be destroyed. I can't understand why Settings activity is be destroyed automatically? How can I make Settings activity still focus when users come back. Code...
View 7 Replies
View Related
Sep 19, 2010
Being an Android newbie experimenting with GPS stuff I managed to put together this code and it works just like I expect it to except for one thing, the GPS icon never goes away. How can get the GPS icon to disappear when the activity is destroyed? I have code...
in my onPause() but apparently that's not enough?
The problem exists in the emulator and also on my HTC EVO with 2.2. On my EVO, the icon stays there when the activity is destroyed and only disappears when I uninstall the app. code...
View 1 Replies
View Related
Aug 4, 2009
When I am running any android project, emuulator will come, but after that in console, its saying
"[DeviceMonitor]Adb connection Error:An existing connection was forcibly closed by the remote host". Then 11 connnection attempts will come in console. I am using windows XP. From windows one dialog box will come saying "adb.exe has encountered a problem and needs to close. We are sorry for the inconvenience."
Because of this, I can't run any project.
View 2 Replies
View Related
Apr 18, 2010
I have tried to freeze orientation: setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
But thought screen stays in portrait orientation, the activity is still recreated.
View 1 Replies
View Related
Jun 30, 2010
I want to do some cleanup in a view when the activity is being destroyed. Is there any way to get a callback in the View when the activity is being destroyed? I tried using onDetachedFromWindow, but I'm not sure whether it is correct thing to do.
View 1 Replies
View Related
Jul 16, 2010
I'm trying to understand remote services at the moment and everything works fine, i can start the service and know how to communicate with it through the AIDL-interface. My problem is that the service seems to still run in the same process like the activity it was started from, because the activity crashes too, if there is an error thrown in the Service.
I set the service process to remote ( android:process=":remote" ) so what am i doing wrong? Or what do i have to do to unbind the service-process completely from the activity-process?
View 1 Replies
View Related
Jul 11, 2012
I am writing a proxy in Android. I want to know, how one may detect if the server or client has closed its socket? I am using pre-NIO sockets. It should be noted that, the YouTube App will connect with my Proxy server (I have installed proxydroid) and then data will pass between YouTube App and Youtube Server through my proxy.
I have used read() method for reading. When I am reading (with read() ) as a client (from the server) if I get -1, does it mean that the server has closed the socket?
In the same way, If I am reading (with read()) from the client and get -1, does it mean that the client has closed the socket?What is the best way to detect if a remote peer has closed the socket or not?If I use methods like isInputShutdown() or isOutputShutdown() ?My main goal is read into a byte array until the remote peer has closed the socket?
View 1 Replies
View Related
Mar 19, 2009
When another activity is started from main activity, The main activity get destroyed and created when returned back from second Activity main activity remains in pause state till second activity finish (), on Sart or on Resume from when returned back from second activity? which one these case does happen in And roid application?
View 3 Replies
View Related
Nov 9, 2010
I'm confused about whether I need to run my service in a separate process. What are the advantages / disadvantages of each?For reference I'm trying to create an App that uses a service to play [streaming] audio in the background. So which one is better for my use case?
View 1 Replies
View Related
Sep 30, 2009
i have an app that binds to a local service.I want to add a desktop widget that binds to the same service. does my service have to be a remote service or can it still be local?if it can still be local, how can I get at the local binder?
View 2 Replies
View Related
Jul 19, 2010
Im writing a program that offers a quick reply dialog upon receipt of an SMS.
However, I am getting an unexpected result. When I receieve an SMS, the appropriate dialog activity comes up displaying the correct phone number and message, however there is a second activity behind it that is the 'default' activity in my program (it is what opens when i launch my application)
I do not want this second activity to come up. The quick reply activity should come up by itself over top of whatever the user was doing before.
The 'floating' activity:
CODE:.........
The call to the activity inside an onReceive()
CODE:..............
The Manifest:
CODE:.................
View 1 Replies
View Related
May 16, 2010
I'm writing an application that starts with a loading activity. In the loading activity the app requests html from web and parses the html, then it sends the parsing result to the main activity. The main activity has several tabs, and contents of these tabs are based on the result of parsing.For example, the result of parsing is a list of strings ["apple", "banana", "orange"], and I need to pass this list to main activity, so that the main activity can create three tabs named after three fruits.I would like to know if there is any way to pass a list of strings among activities, BTW, is it the common way of do this?
View 2 Replies
View Related
Jan 10, 2010
I created an application which enables the user to set whether he wants to receive notification while the application runs in background mode. If the notifications are enabled an activity should be started (the dialog should appear on the screen).
I tried to enabled it the following way:
CODE:...........
This is the method from main activity. When onPause() is executed isRunningInBackground is set true.
When I tried to debug it when the main application was running in the background the line
startActivity(intent) had no effect (the activity didn't appear).
Does anyone know how to midify the logic in order to start an activity from the main activity when the main activity is running in the background (after onPause() is called)?
View 1 Replies
View Related
Dec 4, 2009
Need an example of how to create/start a new activity from the main activity. I have a button click event on the main layout. Originally I just used setContentView(R.layout.secondactivity); which brings up the layout but I don't think that is correct since the secondactivity class is not instantiated at this point yet. I have looked for such an example and can not find one.
View 3 Replies
View Related
Jan 10, 2010
I hav an app that is like a relational database. There is a main app activity that users manage things with. There is also a widget that will display important info and add data to the database. When the widget is clicked, a configure class displays a way for the user to edit data. When the configure activity is done, the widget is updated and instead of going back to the home screen, the apps main activity is started. I can't find where the main activity is being called from. Wouldn't I have to create an intent and start Activity() to get this behavior? When done updating, I want the home screen and not my app.
View 3 Replies
View Related
Nov 7, 2010
I have a main activity, then i call a new activity intent from this. Lets call this SecondActivity. Then from my secont activity i call a browser intent. Then my browser intent call my second activity's onNewIntent method.Evereything work fine, but when i click on "back" button on my phone on my second activity, i will not going to my main activity, but the browsers activity, why?
View 1 Replies
View Related