I build two XML-files for my activity. One in the layout Folder and the other in the layout-land folder. But when I change the orientation from portrait to landscape mode the activity relaunches. And thats exactly what i not want. Because I'm plotting in three Graphs realtime data and the plotting should continue when I turn the Screen and not being interrupted or start new in any way.
Here is the first XML file in the layout-land Folder:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="496dp"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:id="@+id/my_layout" >
<com.jjoe64.graphview.GraphView
android:id="@+id/sensor1_graph_Feuchtigkeit"
android:layout_width="match_parent"
android:layout_height="270dp"
android:layout_alignLeft="@+id/sensor1_graph_Druck"
android:layout_alignParentTop="true" />
<com.jjoe64.graphview.GraphView
android:id="@+id/sensor1_graph_Temperatur"
android:layout_width="match_parent"
android:layout_height="270dp"
android:layout_alignLeft="@+id/sensor1_graph_Feuchtigkeit"
android:layout_below="@+id/sensor1_graph_Feuchtigkeit"
android:layout_marginTop="8dp" />
<com.jjoe64.graphview.GraphView
android:id="@+id/sensor1_graph_Druck"
android:layout_width="match_parent"
android:layout_height="270dp"
android:layout_below="@+id/sensor1_graph_Temperatur"
android:layout_centerHorizontal="true"
android:layout_marginTop="8dp" />
<Switch
android:id="@+id/mySwitch"
android:layout_width="wrap_content"
android:layout_height="30dp"
android:layout_below="@+id/sensor1_graph_Druck"
android:layout_centerHorizontal="false"
android:layout_marginTop="8dp"
/>
<TextView
android:id="@+id/TextView01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/switchStatus"
android:layout_alignParentBottom="true"
android:text="Medium Text"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="@+id/switchStatus"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/mySwitch"
android:layout_alignBottom="@+id/mySwitch"
android:layout_marginLeft="15dp"
android:layout_toRightOf="@+id/mySwitch"
android:text="Medium Text"
android:textAppearance="?android:attr/textAppearanceMedium" />
<Switch
android:id="@+id/switch1"
android:layout_width="wrap_content"
android:layout_height="30dp"
android:layout_alignLeft="@+id/mySwitch"
android:layout_alignParentBottom="true"
/>
</RelativeLayout>
</ScrollView>
And here the second one in layout Folder:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="496dp"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:id="@+id/my_layout" >
<com.jjoe64.graphview.GraphView
android:id="@+id/sensor1_graph_Feuchtigkeit"
android:layout_width="match_parent"
android:layout_height="130dp"
android:layout_alignLeft="@+id/sensor1_graph_Druck"
android:layout_alignParentTop="true" />
<com.jjoe64.graphview.GraphView
android:id="@+id/sensor1_graph_Temperatur"
android:layout_width="match_parent"
android:layout_height="130dp"
android:layout_alignLeft="@+id/sensor1_graph_Feuchtigkeit"
android:layout_below="@+id/sensor1_graph_Feuchtigkeit"
android:layout_marginTop="8dp" />
<com.jjoe64.graphview.GraphView
android:id="@+id/sensor1_graph_Druck"
android:layout_width="match_parent"
android:layout_height="130dp"
android:layout_below="@+id/sensor1_graph_Temperatur"
android:layout_centerHorizontal="true"
android:layout_marginTop="8dp" />
<Switch
android:id="@+id/mySwitch"
android:layout_width="wrap_content"
android:layout_height="30dp"
android:layout_below="@+id/sensor1_graph_Druck"
android:layout_centerHorizontal="false"
android:layout_marginTop="8dp"
/>
<TextView
android:id="@+id/TextView01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/switchStatus"
android:layout_alignParentBottom="true"
android:text="Medium Text"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="@+id/switchStatus"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/mySwitch"
android:layout_alignBottom="@+id/mySwitch"
android:layout_marginLeft="15dp"
android:layout_toRightOf="@+id/mySwitch"
android:text="Medium Text"
android:textAppearance="?android:attr/textAppearanceMedium" />
<Switch
android:id="@+id/switch1"
android:layout_width="wrap_content"
android:layout_height="30dp"
android:layout_alignLeft="@+id/mySwitch"
android:layout_alignParentBottom="true"
/>
</RelativeLayout>
</ScrollView>
In the Manifest XML it Looks like this:
<activity
android:name="com.TomKun.testgraph.DruckActivity"
android:label="@string/Sensor_1"
android:launchMode="singleTask"
android:configChanges="orientation|screenSize|keyboard|keyboardHidden">
</activity>
If i have Manifest like this with
android:configChanges="orientation|screenSize|keyboard|keyboardHidden">
</activity>
Then the layout does not change when I switch from Portrait to landscape mode. BUT the activity does not relaunch. Thats the one good thing
But if I do NOT use
android:configChanges="orientation|screenSize|keyboard|keyboardHidden">
</activity>
the layout changes as i want but the activity is then relaunching.
So something in my implementation doesn't match.
Can anyone help me to solve this Problem?
I have seen that many people have similar Problems here on stackoverflow. But with these answers I couldn't solve my problem
Thanks in Advance!