android - ScrollView not scrolling and application restart on orientation change -


i building android application connects bluetooth module. when application created, thread connect module executed. when rotate phone, application restarts , connection thread run again. around this, added

android:configchanges="orientation|screensize" android:windowsoftinputmode="adjustresize|statehidden" 

to android manifest file. application doesn't restarted, scrollview used in activity not scroll. idea scrollview scrollable , prevent application restarting?

here xml file

    <relativelayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="fill_parent" android:layout_height="fill_parent">  <scrollview     android:layout_width="match_parent"     android:layout_height="match_parent"     android:fillviewport="true"     android:layout_above="@+id/imageview">      <linearlayout         android:id="@+id/linear"         android:layout_width="fill_parent"         android:layout_height="match_parent"         android:layout_above="@+id/imageview"         android:background="#bf000000"         android:orientation="vertical"         tools:context=".mainactivity">          <textview             android:id="@+id/txtreceive1"             android:layout_width="wrap_content"             android:layout_height="wrap_content"             android:visibility="gone" />          <tablelayout             android:id="@+id/table"             android:layout_width="match_parent"             android:layout_height="wrap_content"             android:background="#fff3f3f2"             android:shrinkcolumns="*"             android:stretchcolumns="*">              <tablerow>                  <textview                     android:layout_width="wrap_content"                     android:gravity="center"                      android:padding="8dip"                     android:text="ch" />                  <textview                     android:layout_width="wrap_content"                     android:gravity="center"                     android:padding="8dip"                     android:text="kwh" />                  <textview                     android:layout_width="wrap_content"                     android:gravity="center"                     android:padding="8dip"                     android:text="load" />                  <textview                     android:layout_width="wrap_content"                     android:gravity="center"                     android:padding="8dip"                     android:text="date" />             </tablerow>              <tablerow>                  <textview                     android:id="@+id/t11"                     android:layout_width="wrap_content"                     android:gravity="center"                     android:padding="8dip"                     android:text="1" />                  <textview                     android:id="@+id/t12"                     android:layout_width="wrap_content"                     android:gravity="center"                     android:padding="8dip" />                  <textview                     android:id="@+id/t13"                     android:layout_width="wrap_content"                     android:gravity="center"                     android:padding="8dip" />                  <textview                     android:id="@+id/t14"                     android:layout_width="wrap_content"                     android:gravity="center"                     android:padding="8dip" />             </tablerow>              <tablerow>                  <textview                     android:id="@+id/t21"                     android:layout_width="wrap_content"                     android:gravity="center"                     android:padding="8dip"                     android:text="2" />                  <textview                     android:id="@+id/t22"                     android:layout_width="wrap_content"                     android:gravity="center"                     android:padding="8dip" />                  <textview                     android:id="@+id/t23"                     android:layout_width="wrap_content"                     android:gravity="center"                     android:padding="8dip" />                  <textview                     android:id="@+id/t24"                     android:layout_width="wrap_content"                     android:gravity="center"                     android:padding="8dip" />             </tablerow>              <tablerow>                  <textview                      android:id="@+id/t31"                     android:layout_width="wrap_content"                     android:gravity="center"                     android:padding="8dip"                     android:text="3" />                  <textview                      android:id="@+id/t32"                     android:layout_width="wrap_content"                     android:gravity="center"                     android:padding="8dip" />                  <textview                      android:layout_width="wrap_content"                     android:gravity="center"                     android:padding="8dip" />                  <textview                      android:id="@+id/t34"                     android:layout_width="wrap_content"                     android:gravity="center"                     android:padding="8dip" />             </tablerow>              <tablerow>                  <textview                      android:id="@+id/t41"                     android:layout_width="wrap_content"                     android:gravity="center"                     android:padding="8dip"                     android:text="4" />                  <textview                     android:id="@+id/t42"                     android:layout_width="wrap_content"                     android:gravity="center"                     android:padding="8dip" />                  <textview                      android:id="@+id/t43"                     android:layout_width="wrap_content"                     android:gravity="center"                     android:padding="8dip" />                  <textview                      android:id="@+id/t44"                     android:layout_width="wrap_content"                     android:gravity="center"                     android:padding="8dip" />             </tablerow>              <tablerow>                  <textview                     android:id="@+id/t51"                     android:layout_width="wrap_content"                      android:gravity="center"                     android:padding="8dip"                     android:text="5" />                  <textview                     android:id="@+id/t52"                      android:layout_width="wrap_content"                     android:gravity="center"                     android:padding="8dip" />                  <textview                     android:id="@+id/t53"                      android:layout_width="wrap_content"                     android:gravity="center"                     android:padding="8dip" />                  <textview                     android:id="@+id/t54"                     android:layout_width="wrap_content"                     android:gravity="center"                     android:padding="8dip" />             </tablerow>         </tablelayout>          <textview             android:id="@+id/txtreceive"             android:layout_width="match_parent"             android:layout_height="wrap_content"             android:layout_alignparentleft="true"             android:layout_alignparentstart="true"             android:layout_below="@+id/table"             android:background="#ff8c00"             android:padding="6dip" />          <linearlayout             android:id="@+id/lin2"             android:layout_width="fill_parent"             android:layout_height="fill_parent"             android:paddingtop="5dp"             android:visibility="visible"             android:weightsum="2">              <linearlayout                 android:id="@+id/rel"                 android:layout_width="fill_parent"                 android:layout_height="match_parent"                 android:layout_weight="1"                 android:orientation="vertical"                 android:visibility="visible"                 android:weightsum="4">                   <relativelayout                     android:layout_width="wrap_content"                     android:layout_height="match_parent"                     android:layout_weight="1">                      <button                         android:id="@+id/imagebutton1"                         android:layout_width="fill_parent"                         android:layout_height="fill_parent"                         android:background="@drawable/btn_01_small"                         android:textcolor="#ffa5ff45" />                      <textview                         android:id="@+id/textview3"                         android:layout_width="wrap_content"                         android:layout_height="wrap_content"                         android:layout_aligntop="@+id/imagebutton1"                         android:layout_centerhorizontal="true"                         android:text="channel"                         android:textsize="22sp" />                      <textview                         android:id="@+id/textview9"                         android:layout_width="wrap_content"                         android:layout_height="wrap_content"                         android:layout_alignbottom="@+id/imagebutton1"                         android:layout_centerhorizontal="true"                         android:text="0"                         android:textcolor="#ffa5ff45"                         android:textsize="22sp" />                  </relativelayout>                  <relativelayout                     android:layout_width="wrap_content"                     android:layout_height="match_parent"                     android:layout_weight="1">                      <button                         android:id="@+id/imagebutton2"                         android:layout_width="fill_parent"                         android:layout_height="match_parent"                         android:background="@drawable/btn_02"                         android:textcolor="#ffa5ff45" />                      <textview                         android:id="@+id/textview6"                         android:layout_width="wrap_content"                         android:layout_height="wrap_content"                         android:layout_aligntop="@+id/imagebutton2"                         android:layout_centerhorizontal="true"                         android:text="kwh"                         android:textsize="22sp" />                      <textview                         android:id="@+id/textview10"                         android:layout_width="wrap_content"                         android:layout_height="wrap_content"                         android:layout_alignbottom="@+id/imagebutton2"                         android:layout_centerhorizontal="true"                         android:text="000.0"                         android:textcolor="#ffa5ff45"                         android:textsize="22sp" />                 </relativelayout>                  <relativelayout                     android:layout_width="wrap_content"                     android:layout_height="match_parent"                     android:layout_weight="1">                      <button                         android:id="@+id/imagebutton3"                         android:layout_width="fill_parent"                         android:layout_height="match_parent"                         android:background="@drawable/btn_03"                         android:textcolor="#ffa5ff45" />                      <textview                         android:id="@+id/textview7"                         android:layout_width="wrap_content"                         android:layout_height="wrap_content"                         android:layout_aligntop="@+id/imagebutton3"                         android:layout_centerhorizontal="true"                         android:text="load"                         android:textsize="22sp" />                      <textview                         android:id="@+id/textview11"                         android:layout_width="wrap_content"                         android:layout_height="wrap_content"                         android:layout_alignbottom="@+id/imagebutton3"                         android:layout_centerhorizontal="true"                         android:text="000"                         android:textcolor="#ffa5ff45"                         android:textsize="22sp" />                 </relativelayout>                  <relativelayout                     android:layout_width="wrap_content"                     android:layout_height="match_parent"                     android:layout_weight="1">                      <button                         android:id="@+id/imagebutton4"                         android:layout_width="fill_parent"                         android:layout_height="match_parent"                         android:background="@drawable/btn_04_small" />                      <textview                         android:id="@+id/textview8"                         android:layout_width="wrap_content"                         android:layout_height="wrap_content"                         android:layout_aligntop="@+id/imagebutton4"                         android:layout_centerhorizontal="true"                         android:text="days"                         android:textsize="22sp" />                      <textview                         android:id="@+id/textview12"                         android:layout_width="wrap_content"                         android:layout_height="wrap_content"                         android:layout_alignbottom="@+id/imagebutton4"                         android:layout_centerhorizontal="true"                         android:text="000"                         android:textcolor="#ffa5ff45"                         android:textsize="22sp" />                  </relativelayout>             </linearlayout>              <linearlayout                 android:id="@+id/rel2"                 android:layout_width="fill_parent"                 android:layout_height="fill_parent"                 android:layout_alignparentright="true"                 android:layout_below="@+id/txtreceive"                 android:layout_weight="1"                 android:orientation="vertical"                 android:visibility="visible"                 android:weightsum="4">                  <relativelayout                     android:layout_width="wrap_content"                     android:layout_height="match_parent"                     android:layout_weight="1">                      <button                         android:id="@+id/imagebutton12"                         android:layout_width="fill_parent"                         android:layout_height="fill_parent"                         android:background="@drawable/btn_01_small"                         android:textcolor="#ffa5ff45" />                      <textview                         android:id="@+id/textview32"                         android:layout_width="wrap_content"                         android:layout_height="wrap_content"                         android:layout_aligntop="@+id/imagebutton12"                         android:layout_centerhorizontal="true"                         android:text="auto on"                         android:textsize="22sp" />                      <textview                         android:id="@+id/textview92"                         android:layout_width="wrap_content"                         android:layout_height="wrap_content"                         android:layout_alignbottom="@+id/imagebutton12"                         android:layout_centerhorizontal="true"                         android:text="00:00"                         android:textcolor="#ffa5ff45"                         android:textsize="22sp" />                  </relativelayout>                  <relativelayout                     android:layout_width="wrap_content"                     android:layout_height="match_parent"                     android:layout_weight="1">                      <button                         android:id="@+id/imagebutton22"                         android:layout_width="fill_parent"                         android:layout_height="match_parent"                         android:background="@drawable/btn_04_small"                         android:textcolor="#ffa5ff45" />                       <textview                         android:id="@+id/textview62"                         android:layout_width="wrap_content"                         android:layout_height="wrap_content"                         android:layout_aligntop="@+id/imagebutton22"                         android:layout_centerhorizontal="true"                         android:text="auto off"                         android:textsize="22sp" />                       <textview                         android:id="@+id/textview102"                         android:layout_width="wrap_content"                         android:layout_height="wrap_content"                         android:layout_alignbottom="@+id/imagebutton22"                         android:layout_centerhorizontal="true"                         android:text="00:00"                         android:textcolor="#ffa5ff45"                         android:textsize="22sp" />                   </relativelayout>                  <relativelayout                     android:layout_width="wrap_content"                     android:layout_height="match_parent"                     android:layout_weight="1">                      <button                         android:id="@+id/imagebutton31"                         android:layout_width="fill_parent"                         android:layout_height="match_parent"                         android:layout_marginbottom="-14dp"                         android:layout_margintop="7dp"                         android:background="@drawable/send_btn_01"                         android:text="set time"                         android:textsize="22sp" />                 </relativelayout>                  <relativelayout                     android:layout_width="wrap_content"                     android:layout_height="match_parent"                     android:layout_weight="1">                      <button                         android:id="@+id/imagebutton32"                         android:layout_width="wrap_content"                         android:layout_height="wrap_content"                         android:layout_marginbottom="-7dp"                         android:background="@drawable/send_btn_01"                         android:padding="0dp"                         android:scaletype="matrix"                         android:text="recharge"                         android:textsize="22sp" />                 </relativelayout>              </linearlayout>         </linearlayout>       </linearlayout> </scrollview>  <imageview     android:id="@+id/imageview"     android:layout_width="match_parent"     android:layout_height="wrap_content"     android:layout_alignparentbottom="true"     android:layout_alignparentleft="true"     android:layout_alignparentstart="true"     android:adjustviewbounds="true"     android:background="#bf000000"     android:src="@drawable/base_irya_left1" /> 

activities destroyed , recreated on screen rotation, , want resizes ui elements properly.

create bluetooth connection/thread in separate singleton class becomes independent of activity, or make relevant activity members static.

however, sure destroy doesn't leak/persist beyond legitimate application lifecycle.


Comments

Popular posts from this blog

python - No exponential form of the z-axis in matplotlib-3D-plots -

php - Best Light server (Linux + Web server + Database) for Raspberry Pi -

c# - "Newtonsoft.Json.JsonSerializationException unable to find constructor to use for types" error when deserializing class -