Android :: Using Socket In Service Communicating With More Activities

Aug 29, 2010

I want to create an application to remote control my PC.

For example: Volume (get actual volume level, increase/decrease/mute volume), TVtime (start/quit tvtime, get actual channel, toggle fulscreen, channel up/down, toggle input source, toggle aspect ratio), Amarok (start/quit amarok, get current song, prev/next song, play/stop/ pause), etc.

The application for the PC is done (in python). The communication protocol used is very simple.

For example: "volume:get_level", "volume:up", "volume:mute", etc. Now I'm working on the android application.

What I have implemented till now is to create an activity, with: - an edittext to enter host:port - a button to connect/disconnect to/from server - the onCreate method creates a new thread for socket communication to send/receive messages to/from PC. - a textview to display information received from PC (eg. volume level) - a button to send command to PC I'm using handler to communicate between the tcpclient thread and the main activity.

It is working... But I want to use more than 1 activity. I want to use different activity for every program controlled. Searching for a solution to transfer the thread's handler to a new activity I have found that it is not possible, and I have to use a service.

So, my question is: how to send message from different activities to the same service, how to send message from service to the actual activity and how can I check in the service which is the actual activity? Because the service is running in the same thread as the activities I suppose that I still have to create a new thread for socket communication. How can I send the data received by the socket to the service?

Android :: Using socket in service communicating with more activities


Android :: Pass Socket - Inputstream - Outputstream Objects Between Activities

Jun 29, 2010

How to pass socket, inputstream, outputstream objects between activities

View 1 Replies View Related

Android :: Managing Activities From Service

Jun 1, 2010

I have a service that listens to the serial port. According to data received from serial i switch between particular service states, and start particular activities on state transitions. I would like to accomplish it in following way: Let's assume there is one active Activity1 started from previous state, I call startActivity from service to start a new one Activity2, but I want to simulatenously destroy Activity1 when Activity2 gets on top of the stack. I tried to call finish() in Activity1.onStop but it seems not to work (Activity1.onDestroy() doesn't get called). I'd prefer to finish Activity1 after Activity2 gets on top in order to avoid blinking.

View 5 Replies View Related

Android :: How Many Activities Bound To Service

Sep 11, 2009

I have a service that's running in the background, is there any way (short of keeping a count of onBind() and onUnbind()) to know the number of activities that are bound to it?

I am trying to provide a "quit" function. all my activities derive from the same base class. I am keeping a global static around that says the "quit" button was pressed. then on each of the activities onResume() method, I look for the global static "quit" variable and if it's set to true, I call "finish()" so my activity shuts down, and then next activity on the task stack appears -- which goes through the same process of checking the global static "quit" variable until it gets to the root activity -- which effectively goes back to the main desktop screen.

However, I need a way to reset the global static "quit" variable, otherwise, when I launch the app again, it will check the global static quit variable and shutdown immediately - never coming back up. So, I want to know if there are any activities bound to my service, if not, I would set the global static "quit" variable back to false so that the app could be relaunched again.

View 2 Replies View Related

Android :: Service - Communicate With Activities

May 19, 2010

I'm wondering which is the best way to communicate between a Service and an activity..

Broadcast intent
Callback
others?...

View 1 Replies View Related

Android :: Service - Not Bound To Any Activities

Jun 5, 2010

I have an Android Service that I would like to keep running even after the last Activity has been popped off the stack, or the User has chosen to do something else.

Essentially the Service is listening for changes on a remote server, and I would like to generate a Notification if and only if an Activity from the app isn't running(or visible). In other words, I don't want the Notifications to occur while the User is directly interacting with the app.

In the case where the User is directly interacting with the app, the Service will notify the Activity and update appropriate UI elements based on the changes. I plan to implement this through the Observer pattern.

How can the Service know if none of apps Activities are bound to it?

View 2 Replies View Related

Android :: Service By Mean Share By All Activities

Aug 27, 2010

Android: i want to create service by extending a Service class which i start when application get started and all activities can share its state and when i want stop it from other activity and when i want start it again from any activity ?

View 1 Replies View Related

Android :: How To Stop Service - When All Activities Are Finished

Jan 26, 2010

I am programming a game. I have a service for the background-music. When I press the home-button and leave my activities, the service still runs in background. How can I stop the service, when there is no more visible activity in my program and restart it, when the user goes back to my game (some activity of it)?

View 8 Replies View Related

Android :: Stop Service Only When There Are No Other Activities In App Running

Mar 13, 2010

Is there a way I can test if there are any other activities in my app still alive? I am looking to stop a service in an onDestroy method, but only want to do this if there are no other activities from my app still alive on the stack.

I have the call stop the service in the main activity's onDestroy() method. This works perfect EXCEPT that if a user launches my app, then launches a few activities in my app, then hits the home screen and RELAUNCHES my app, they will subvert my order and the main activity will now be above other activities of my app. From this state, if they hit the back button and 'back out' of my home screen they will trigger the onDestroy() method and kill the service even though there are other activities open on the stack. I want to avoid this by stopping the service ONLY if I am sure there are no other activities of mine open on the stack.

View 1 Replies View Related

Android :: Service Object Availability Between Activities

Apr 3, 2010

I currently have a service called ConnectionService. It instantiates a Connection object that gives me access to a controller of TCP.

I start the service from a splash screen activity, which sends and intent and starts my "main" activity once a connection has been established. In the "main" activity, I can access my Connection object and communicate with the controller. However, when I start a new activity from the "main" activity and bind to the service, I get a NullPointerException when I try to call methods in the ConnectionService.

View 11 Replies View Related

Android :: Multiple Activities Binding To A Service

Aug 3, 2010

I have a service component (common task for all my apps), which can be invoked by any of the apps. I am trying to access the service object from the all activities, I noticed that the one which created the service [startService(intent)] has the right informaion. But rest does not get the informaion needed.

My Code is as below:

CODE:................

If I invoke startService(intent). it creates a new service and runs in parallel to the other service.

If I don't invoke startService(intent), serviceObj.getData() retuns null value.

View 1 Replies View Related

Android :: Service Interacting With Multiple Activities

Jun 29, 2010

I'm trying to refactor/redesign an Android app. Currently, I've one UI activity (Activity 1) that creates a DataThread. This thread is responsible for network I/O and interacts (provides data) with the UI activity via a handler.

Now, I want to add another activity (a new UI screen with Video) - Activity 2. Activity 1 is still the main activity. Activity 2 will be invoked when the user clicks a button on Activity 1. Activity 2's data also comes from the DataThread.

My idea is to put the logic of my DataThread inside an Android Service (DataService). My question is - can more than on activity bind to my DataService at the same time? Is there a way to tell the service to provide data to a specific activity only?

View 1 Replies View Related

Android :: Java Socket Not Throwing Exceptions On Dead Socket?

Jun 29, 2010

We have a simple client server architecture between our mobile device and our server both written in Java. An extremely simple ServerSocket and Socket implementation. However one problem is that when the client terminates abruptly (without closing the socket properly) the server does not know that it is disconnected. Furthermore, the server can continue to write to this socket without getting any exceptions. Why? According to documentation Java sockets should throw exceptions if you try to write to a socket that is not reachable on the other end!

View 5 Replies View Related

Android :: Bind Service To Multiple Activities Advice

May 19, 2010

I'm new to Android development and am working on a small test project. I have a service, which communicates with an SQLite3 database, and two activities. A main activity which fetches database information via the service and displays it and a second activity which allows me to add data to the database via the service.

Currently, I have a singleton class which implements the ServiceConnection interface and I'm binding this to the service in the the main activity using the bindService function. Because it's a singleton, I can then use this service connection in both the main activity and second activity to work with the database and it all seems to work quite well.

However, I'm all the time aware that the service connection is bound to the main activity and I'm wondering if this is the wrong/bad way to do it? Would I be best off having two service connections, one in each activity, and binding each to the service?

View 2 Replies View Related

Android :: Handling Events From One Service For Multiple Activities

Jun 10, 2010

I have a class A which extends TabActivity and creates Activities B, C and D as tabs in its onCreate() function. Also, class A initializes another service handler class S which is responsible for establishing a connection to a service and implementing callback handlers for the service. Any of the Activities B, C and D should be able to receive events from the service and update accordingly. If I receive any event in class S from the the service then I want to call a function in Activity B which would be responsible to update the UI elements in Activity B based on the event received. You can assume that the user is in Activity B when the event arrives.

Can I call an activity function like the following in the stub handler for the callback in my class S -

CODE:................

View 4 Replies View Related

Android :: One Local Service Multiple Binding Activities

Nov 20, 2010

I have a local Service to which multiple activites needs to bind. In the first launched Activity, bindService returns true and onServiceConnected is called. But in any additionally launched activites bindService returns false, and I can't get a reference to my Service.

How can multiple activities simultaneously be connected to a local Service?

View 3 Replies View Related

Android :: Communication Between Activities - Intent Or Service - Faster

May 3, 2010

Is there a significant difference in time needed for sending data over a service or by using an intent?

Are there general advices when to use service and when to use intents?

View 4 Replies View Related

Android :: Want Connected To Phone Service Between Multiple Activities?

Jan 15, 2010

I have multiple activities and one service.. In MainActivity I successfully connect to service (using a class what implements ServiceConnection + bindService() + startService()) but when i try to apply same method in other activity i see in LogCat a error... It Is possible to connect to service in an other way: something like to make static my CounterServiceConnection object in MainActivity and use it in the second one?

View 2 Replies View Related

Android :: Socket Programming - Java - Many Clients One Socket

Nov 12, 2009

Essentially Im trying to get many many java clients connect to a socket on my ColdFusion server (Using the Socket Gateway). However before i even start to code this, Im a little confused about sockets and their performance. First of all, are sockets meant for many(1000+) clients connecting to one socket (say port 2202) on one server? How is the performance if all there waiting for is basically a ping, or something such that when these clients receive this "ping" they can go get some new data.

View 5 Replies View Related

Android :: Service Change Values Of Variables And UI Textfields Of Activities

Oct 20, 2010

I have an application that get/send data from/to a remote DB on internet.

I need to get my application working in background mode, then i supose that i have to put all the send/get remote data in a service..... but.... How can this service change values of variables and UI textfields of my activities? i can't find any information about this, all the tutorials i am finding are of simple services that doesn't do something like that.

View 7 Replies View Related

Android :: Background Service To Recode Different Activities And Upload On Server

Sep 9, 2010

I want to know that how i can get these things in android.Recording of Calls Appointment/Calendar Logging Bookmark Logging Browser History Logging Contact Details Location Through SMS SIM Change Notification and after getting these things in a file (.txt, xml, or CSV) how i can upload these things to my php server by running a backgroud service.Service will now prompt user again and again. Everything will be recorded silently and then user will see this information on server whenever required.

View 2 Replies View Related

Android :: Connecting Android Bluetooth Client Socket To Ubuntu Server Socket

Jul 15, 2010

I am writing an Android app that should exchange data to a server over Bluetooth, with the server side on a PC running Ubuntu, using the bluez library, in C (or C++).

My Android app fails (IOException) when I try to connect to my server socket on the PC.

Here is essentially what I in the java code (in Android, full eclipse project here: http://dl.dropbox.com/u/2968234/ThinBTClient.zip)

CODE:...........

This throws IOException after a timeout of 10seconds or so.

On the server side (in Ubuntu 8.10), I basically set up a Bluetooth server socket, along the lines described in the example bluez/sdp-register.c

Down below is my C++ program. To compile it do

g++ -I/usr/include/glib-2.0/ -I/usr/lib/glib-2.0/include -o bt_server bt_server.cpp -lbluetooth

I can do the reverse succesfully, i.e. create a server socket in Android and connect from Linux, however this is not what I want to do!

I think either the problem has to do with my config of Ubuntu.

CODE:................

View 1 Replies View Related

Android :: Socket Exception Socket Not Connected Android

Oct 27, 2010

In my android application i am trying to run a application using GPRS connection and not WIFI.When tried to run in wifi the app runs fine.The browser works fine with the APN settings set but when trying to connect to server using my application it gives me socket exception.I am using the below permissions in manifest file.
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"></uses-permission>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"></uses- permission>
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE"></uses-permission>
<uses-permission android:name= "android.permission.CHANGE_NETWORK_STATE"></uses-permission>
<uses-permission android:name= "android.permission.WRITE_APN_SETTINGS" ></uses-permission>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" ></uses-permission>
I am receiving Socket not connected exception.Is there any other permission which i need to add for using GPRS connection other than WIFI.
10-27 18:26:19.689: WARN/CalSyncSvc(166): com.motorola.blur.service.email.protocol.activesync.ASException: Problem executing HTTP POST

10-27 18:26:19.689: WARN/CalSyncSvc(166): at com.motorola.blur.service.email.protocol.activesync.ActiveSyncMgr.sendRequest(Unknown Source)
10-27 18:26:19.689: WARN/CalSyncSvc(166): at com.motorola.blur.service.email.protocol.activesync.ActiveSyncMgr.sendXMLCommandNoProvisoning(Unknown Source)
10-27 18:26:19.689: WARN/CalSyncSvc(166): at com.motorola.blur.service.email.protocol.activesync.ActiveSyncMgr.sendXMLCommand0(Unknown Source)
10-27 18:26:19.689: WARN/CalSyncSvc(166): at com.motorola.blur.service.email.protocol.activesync.ActiveSyncMgr.sendXMLCommand(Unknown Source)
10-27 18:26:19.689: WARN/CalSyncSvc(166): at com.motorola.blur.service.email.protocol.activesync.ActiveSyncMgr.sendFolderSyncCommand(Unknown Source)
10-27 18:26:19.689: WARN/CalSyncSvc(166): at com.motorola.blur.service.email.protocol.activesync.ProviderAPI.sendFolderSync(Unknown Source)
10-27 18:26:19.689: WARN/CalSyncSvc(166): at com.motorola.blur.service.email.protocol.activesync.ProviderAPI.updateMapFromFolderSync(Unknown Source)
10-27 18:26:19.689: WARN/CalSyncSvc(166): at com.motorola.blur.service.email.protocol.activesync.ProviderAPI.updateFromFolderSync(Unknown Source)
10-27 18:26:19.689: WARN/CalSyncSvc(166): at com.motorola.blur.calendar.sync.activesync.SyncService.syncAccount(Unknown Source)
10-27 18:26:19.689: WARN/CalSyncSvc(166): at com.motorola.blur.calendar.sync.activesync.SyncService$QueueEntry.run(Unknown Source)
10-27 18:26:19.689: WARN/CalSyncSvc(166): at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:416)
10-27 18:26:19.689: WARN/CalSyncSvc(166): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:256)
10-27 18:26:19.689: WARN/CalSyncSvc(166): at java.util.concurrent.FutureTask.run(FutureTask.java:122)
10-27 18:26:19.689: WARN/CalSyncSvc(166): at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:648)
10-27 18:26:19.689: WARN/CalSyncSvc(166): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:673)
10-27 18:26:19.689: WARN/CalSyncSvc(166): at java.lang.Thread.run(Thread.java:1058)
10-27 18:26:19.689: WARN/CalSyncSvc(166): at com.motorola.blur.util.concurrent.BlurThreadFactory$BlurPooledThread.run(Unknown Source)
10-27 18:26:19.689: WARN/CalSyncSvc(166): Caused by: java.net.SocketTimeoutException: Socket is not connected
10-27 18:26:19.689: WARN/CalSyncSvc(166): at org.apache.harmony.luni.platform.OSNetworkSystem.connectStreamWithTimeoutSocketImpl(Native Method)


10-27 18:26:19.689: WARN/CalSyncSvc(166): at org.apache.harmony.luni.platform.OSNetworkSystem.connectStreamWithTimeoutSocket(OSNetworkSystem.java:140)
10-27 18:26:19.689: WARN/CalSyncSvc(166): at org.apache.harmony.luni.net.PlainSocketImpl.connect(PlainSocketImpl.java:229)
10-27 18:26:19.689: WARN/CalSyncSvc(166): at org.apache.harmony.luni.net.PlainSocketImpl.connect(PlainSocketImpl.java:521)
10-27 18:26:19.689: WARN/CalSyncSvc(166): at java.net.Socket.connect(Socket.java:1019)
10-27 18:26:19.689: WARN/CalSyncSvc(166): at org.apache.http.conn.ssl.SSLSocketFactory.connectSocket(SSLSocketFactory.java:317)
10-27 18:26:19.689: WARN/CalSyncSvc(166): at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:129)
10-27 18:26:19.689: WARN/CalSyncSvc(166): at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:164)
10-27 18:26:19.689: WARN/CalSyncSvc(166): at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:119)
10-27 18:26:19.689: WARN/CalSyncSvc(166): at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:348)
10-27 18:26:19.689: WARN/CalSyncSvc(166): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555)
10-27 18:26:19.689: WARN/CalSyncSvc(166): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)
10-27 18:26:19.689: WARN/CalSyncSvc(166): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465)
10-27 18:26:19.689: WARN/CalSyncSvc(166): ... 17 more

View 2 Replies View Related

Android :: Communicating With PC - C#

Jan 13, 2010

I want to create an application in Android which communicates with a server application (written in C#, doesn't matter what version of .NET) on the PC via TCP/IP. I was thinking about some kind of RPC like SOAP or XML-RPC. But I want to keep the server application as light and simple as possible. And I think in C# you rely on a Webserver to set up an RPC server. Or maybe is it better to communicate directly via the TcpListener?

View 2 Replies View Related

Android :: Not Communicating With Computer

Jan 20, 2010

I plugged my Hero, via USB cable, into my computer. The charge light is on but my computer is not seeing the device. I have rebooted the phone and the computer and it still won't see the device.

View 1 Replies View Related

Android :: Communicating Between An App And A Widget

May 10, 2010

Whether its possible for an application and a widget to communicate data to each other directly? Basically I'd need the app to be able to check that the widget is running/visible, and would need the app to send information to the widget. I'm far from actually implementing anything yet, so I'm not really looking for any overly detailed explanations, just if whether or not what I'm looking to achieve is possible.

View 2 Replies View Related

Android :: Communicating With The PC Via USB Connection

Apr 12, 2010

I'm fairly new to android programming and need some information for a 4th year forensics course project. Basically I am trying to create a suite of tools for live analysis of an android phone. I know how to get the information I need on the phone, but I was wondering if there was a way to communicate that information back to the PC? I want to be able to run a program from a PC, which, when the phone is docked, will allow the user to access information about the phone (ie currently running services/processes, bluetooth/wifi connections, etc). I have a bunch of methods that will run on the phone and get all the information, but I want to be able to call those methods from the PC, execute on the phone, then have the information sent back to the PC to display to the user instead of just displaying it on the phone. This is to leave as small a footprint on the phone as possible.

View 1 Replies View Related

Android :: Communicating With Servers

Oct 18, 2010

I come from a .Net background and recently x-training to java.

I wanted to develop an Android application that required simple functionality to communicate with a server. For example, functionality such as post a username/score to a website (or service), or request information such as top 10 scores.

What type of communications should I focus on? What is the common technology to use? Does Java have the equivalent of WCF? Or does it have some sort of simple web service? Can web services be secured with authentication?

Ive heard other references to xml-rpc. Should this be something I should look into?

View 3 Replies View Related

Android :: Switching Activities / Passing Data Between Activities

Jun 30, 2010

how to call BarCodeScanner, and return the value to a field.so now, i have a toast that says "successful scan" and then i want to pass the result to a new activity. when i comment out my intent, everything works (minus the passing of data/switching of screen, obviously) but when i run my project as is, it FC's no errors reported by eclipse in code or xml. any insights?

View 2 Replies View Related

Android :: Communicating With A Looper Thread

Feb 9, 2009

I need a message queue in my background thread, so I created a looper thread.

CODE:...................

View 5 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved