However, thank you very much for your help. Also tried to implement it
without singleton now and I just have the same weired problem.... :-(

On 6 Feb., 18:49, Bob Kerns <r...@acm.org> wrote:
> In addition to the comment/correction by Streets of Boston...
>
> It's unclear from your description just where you're storing your non-
> static variables. The right way would appear to be in your
> ServerConnection instance, since that's the static singleton. Your
> activity will have a much shorter lifespan.
>
> There's a fair bit more that's unclear to me from your description as
> well. It may be that you need to create and bind a service
> (android.app.Service). I'm not sure you're using "ServerConnection",
> and "server connection" in the sense of a connection to an
> android.app.Service, or to a service on some other system accessed via
> your socket connection.
>
> I'm not sure why you had trouble passing data from your activity to
> your service. If it was an android.app.Service, look at aidl.
>
> Without an android.app.Service, your entire application could be going
> away in between times, if it's not in the foreground. Be sure you
> understand the application and activity lifecycle. Your choice of
> whether to use an android.app.Service should be based on how the
> application lifecycle matches up with when you need this connection to
> exist and what you're doing with it.
>
> If you need it to persist solely to avoid authentication, consider
> getting a time-limited authentication token back instead, and
> persisting that. This would allow your activity, service, connection,
> and entire application to go away, and be restarted, and the user
> would still avoid re-authenticating. You can refresh the token with a
> new time-limited token on each reconnect or access, so timeout will
> only happen if the user is idle for an extended period. This can give
> a more robust user experience.
>
> Still, I think there's a good chance the problem is that you wrote:
>
> public static ServerConnection getInstance() {
>       if(m_connection == null)
>           return new ServerConnection();  // instead of m_connection =
>       return m_connection;
>
> }
>
> I hope this helps, somehow. I know it's hard to do when you're lost,
> but if you can better describe your circumstance, you can get more
> useful answers. (Sometimes, doing so even leads you to your own
> answer!)
>
> On Feb 6, 4:08 am, Florian Lettner <fl.lett...@gmail.com> wrote:
>
> > Hey guys,
> > I seriously need help with a quite strange problem. I created a client
> > which communicates with a server. Therefore, I have three classes. An
> > activity providing a nice dialog to configure some data, a background
> > service which checks the connection status periodically and a server
> > class which handles the socket connection. Originally, the background
> > service owned a server connection object but because I could not
> > manage to provide data from the activity to the service, I decided to
> > create the server connection class as singleton.
>
> > The user is now able to change data in the activity (IP, Port,
> > Username, Password) which shall be transmitted to the server object,
> > if the save button is pressed. The data is read correctly, the
> > activity calls the setter of the server class and the logcat also says
> > that this data is correctly applied to the variable that stores the
> > data in the server class. However, if I try to start the socket
> > connection still the old values are stored in my variables although
> > they've been overwritten before. What I am doing wrong, or how can I
> > fix this?
>
> > My singleton looks like this.
>
> > static ServerConnection m_connection;
>
> > public static ServerConnection getInstance() {
> >       if(m_connection == null)
> >           new ServerConnection();
>
> >       return m_connection;
>
> > }
>
> > All getters/setters and other variables are non-static.
>
> > Best regards,
> > Florian

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to