i have a class,

class myapp // for example
// some variables used by UI and telnet class
// i.e. my edit text controls and telnet object
// initiate UI elements like 2 edittext controls and ascroller and a button
// start telnet thread

class telnet {
// telnet can post new messages to edittext window through handler

}// end telnet

}// end program

the problem is when oncreate is called again, like they flip the phone, by default it recreates the telnet thread and the users if forced to reconnect.

i checked if savedinstancestate is not null and tried to bypass this, but then it just stops. It's like the old telnet thread is no longer connected to the UI if i don't restart it, though from what i can tell they are still connected.

I see there are ways to add data to saved instance state, but the methods are like add a Boolean or add a string, i don't see how to save my telnet object that is represented by a nested class. And I'm not sure even if i did that, if it would keep the socket open.

i added:

android:configChanges="keyboardHidden|orientation" to my applications manifest in the activity section and added the method:

	public void onConfigurationChanged(Configuration newConfig) {

which means now on a phone flip i'm telling it in the manifest that i'll handle it in my method i added, where i do nothing, and it works to not re-initialize the application. The phone flips, it redraws and the application state doesn't change so oncreate is not called and I don't get disconnected from the internet.

This is good enough for now. There are still other changes that can happen like they toggle to another application i guess, that would cause oncreate to be called and i'll have to eventually learn to handle this. In my reading i saw something about creating a class application to handle stuff you only want to initialize once. So i may eventually look into that. Also i saw that there is a way to use the savedInstanceState, to set all my stuff in the layout that has a layout id back to its previous state instead of recreating it. So it looks like i'd be

if(savedInstanceState != null)
// initialize components from the saved state
// do the normal mybutton =(Button)findViewByID(etc..

My thinking is since the telnet does not appear to die, no disconnection on the server, the telnet just lost its connection to any controls, if i choose to not make a new telnet object. So if all my controls were restored to the previous state, maybe that wouldn't happen. dont know. sort of a question of if the savedInstanceState restores the same reference maybe.

Anyway what i got working for now, will get me through a phone flip.


commented: Well done. Thanx for sharing +14