0

i wrote a public class, which handle a ethernet communication, has some thread that update some variables.

The main activity interact with this class getting the variables or to send some messages. So after a orientation change thread are running as I want but the main activity it can not get datas from the "ethernet class".

How I declare the class in the main activity:

EthIp = new EthIp(tot_in, tot_out, IP , Port, false);

Start thread in the EthIP class

Thank you for hlep...

torex
  • 3
  • 1

2 Answers2

0

Remember that at default Activity is destroyed and then created a new one during orientation change (link)

Make sure you close eth connection in OnClose/OnPause method of an Activity and that the threads you create behave appropriately when you restart your Activity.

Community
  • 1
  • 1
sygi
  • 4,557
  • 2
  • 32
  • 54
0

When orientation changed your activity should have recreated and a new ethernet class instance created. You have to avoid activity recreate. change your manifest as...

    <activity android:name=".activity.MainActivity"
        android:configChanges="keyboardHidden|orientation|screenSize">
    </activity>

and then override onConfigurationChanged() in the activity as ...

@Override
public void onConfigurationChanged(Configuration newConfig)
{
    super.onConfigurationChanged(newConfig);
}
Libin
  • 16,967
  • 7
  • 61
  • 83
  • Thanks Libin, this works as I wanted... A doubt, this solution doesn't prevents me to change layout or fragment in that activity? Thanks again – torex Mar 24 '14 at 20:04
  • Yes, If you need to have different layout for portrait/landscape , then your activity have to recreated. but when it recreate activity savedInstanceState will not be null. you have to save your state on orientation change. – Libin Mar 24 '14 at 20:09