1

Let me quickly introduce myself: over 30 years of programming in general, over 12 years of Java, less than 3 weeks of Android.

My question is about my architecture/design. Being so novice in Android, I wonder if the whole idea makes sense. Basically, I want to build a Telnet-like terminal. Such a terminal normally has a long-lived TCP connection that would be nice not to be dropped every time the activity that displays the screen goes away or whenever Android feels like it. My idea is to use a service that keeps the connection open and contains the current telnet screen contents. When the activity is (re)created, it starts the service and retrieves the screen contents and the connection (java.net.Socket). It displays the contents and uses the socket for further user interraction. If the user intentionally disconnects, only then I stop the service.

To avoid the user forgetting that his telnet session is open somwhere in the background, I would also put something in the notification area while the service is running.

Thanks!

baftoid
  • 13
  • 4

1 Answers1

0

You should take a look at Android: keeping a background service alive (preventing process death)

Basically you can start your service this way, with a notification being shown to the user, so that the system will not kill your service (under normal circumstances).

So Android sort of requires that you show the user a notification if you are going to keep something running, and if you do that then in turn it will not kill your service.

Community
  • 1
  • 1
skynet
  • 9,898
  • 5
  • 43
  • 52
  • Thanks for your very useful answer. I apreciate especially the startForeground() tip: not only it helps with the notification, but also increases my chance not to be killed. The fact that you don't say anything negative about my whole plan, sort of confirms that it is sound. By the way, is there any way to 'reward' answers here? – baftoid Dec 10 '11 at 14:49
  • @baftoid yeah on questions you ask you can click the check mark on the left (see [here](http://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work)) and when you get enough rep you can click the up arrow next to questions or answers you like – skynet Dec 10 '11 at 19:31