I connect to i ip-cam with thread. When I rotate screen, activity restart and new thread restart?? I only want to set ImageView fullscreen when ı rotate... How can I stop activity-restart???
public class ViewCam extends Activity implements OnClickListener {
private Bitmap bmp = null;
private String bmpl = null;
private ImageButton UpButton;
private ImageButton DownButton;
private ImageButton LeftButton;
private ImageButton RightButton;
private ImageButton ZoomInButton;
private ImageButton ZoomOutButton;
private ImageButton butlisten;
ImageView imageView;
TextView imagetext;
long id;
Thread My;
private Runnable viewCams;
private ProgressDialog m_ProgressDialog = null;
private ArrayList<ImageView> imageArray;
private Gallery gallery;
private Handler handler = new Handler() {
public void handleMessage(Message msg) {
try {
bmp = CameraManagerScreen.ActiveCam.getCurrentImage();
bmpl = CameraManagerScreen.ActiveCam.getCurrentLenght();
if (bmp != null) {
if (CameraManagerScreen.ActiveCam.isConnected())
m_ProgressDialog.dismiss();
imageView.setImageBitmap(bmp);
imagetext.setText(bmpl);
}
} catch (Exception e) {
} finally {
sleep();
}
};
public void sleep() {
this.removeMessages(0);
sendMessageDelayed(obtainMessage(0), 50);
};
};
protected void onStart() {
super.onStart();
if (CameraManagerScreen.ROTATION == 0) {
My = new Thread() {
public void run() {
try {
CameraManagerScreen.ActiveCam.go();
// upLoadCam();
} catch (Exception ex) {
}
};
};
My.start();
}
}
@Override
public void onConfigurationChanged(Configuration newConfig) {
// TODO Auto-generated method stub
super.onConfigurationChanged(newConfig);
CameraManagerScreen.ROTATION = 1;
}
@Override
protected void onStop() {
CameraManagerScreen.ActiveCam.cancel();
CameraManagerScreen.ActiveCam.setConnected(false);
super.onStop();
}
@Override
public void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setFullscreen();
setContentView(R.layout.viewcam);
imageView = (ImageView) findViewById(R.id.myView);
imagetext = (TextView) findViewById(R.id.imageText);
gallery = (Gallery) findViewById(R.id.gallery);
UpButton = (ImageButton) findViewById(R.id.UpButton);
DownButton = (ImageButton) findViewById(R.id.DownButton);
LeftButton = (ImageButton) findViewById(R.id.LeftButton);
RightButton = (ImageButton) findViewById(R.id.RightButton);
ZoomInButton = (ImageButton) findViewById(R.id.ZoomInButton);
ZoomOutButton = (ImageButton) findViewById(R.id.ZoomOutButton);
UpButton.setOnClickListener(this);
DownButton.setOnClickListener(this);
LeftButton.setOnClickListener(this);
RightButton.setOnClickListener(this);
ZoomInButton.setOnClickListener(this);
ZoomOutButton.setOnClickListener(this);
// gallery.setOnClickListener(this);
if (CameraManagerScreen.ROTATION == 0) {
m_ProgressDialog = ProgressDialog.show(ViewCam.this,
"Please wait...", "Connecting ...", true);
m_ProgressDialog.setCancelable(true);
m_ProgressDialog.setCanceledOnTouchOutside(true);
// Thread gThread=new Thread(){
// public void run(){gallery.setAdapter(new ImageAdapter(this));}
// };
handler.sendMessage(new Message());
}
}
public void setFullscreen() {
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
}
private Runnable returnRes = new Runnable() {
public void run() {
// if (cameras != null && cameras.size() > 0) {
// c_adapter.notifyDataSetChanged();
// for (int i = 0; i < cameras.size(); i++)
// c_adapter.add(cameras.get(i));
// }
// m_ProgressDialog.dismiss();
// c_adapter.notifyDataSetChanged();
}
};
// private void upLoadCam() {
// imageArray = new ArrayList<Bitmap>();
// for (int i = 0; i < CameraManagerScreen.cameras.size(); i++) {
// if(CameraManagerScreen.cameras.get(i)
// .getImageForGallary()!=null)
// imageArray.add(CameraManagerScreen.cameras.get(i)
// .getImageForGallary());
// }
// }
@Override
public void onClick(View v) {
if (v == UpButton) {
Thread t = new Thread() {
public void run() {
try {
CameraManagerScreen.ActiveCam.goPTZ(CameraType.PTZ_UP);
} catch (Exception ex) {
}
};
};
t.start();
}
if (v == DownButton) {
Thread t = new Thread() {
public void run() {
try {
CameraManagerScreen.ActiveCam
.goPTZ(CameraType.PTZ_DOWN);
} catch (Exception ex) {
}
};
};
t.start();
}
if (v == LeftButton) {
Thread t = new Thread() {
public void run() {
try {
CameraManagerScreen.ActiveCam
.goPTZ(CameraType.PTZ_LEFT);
} catch (Exception ex) {
}
};
};
t.start();
}
if (v == RightButton) {
Thread t = new Thread() {
public void run() {
try {
CameraManagerScreen.ActiveCam
.goPTZ(CameraType.PTZ_RIGHT);
} catch (Exception ex) {
}
};
};
t.start();
}
if (v == ZoomInButton) {
Thread t = new Thread() {
public void run() {
try {
CameraManagerScreen.ActiveCam
.goPTZ(CameraType.PTZ_ZOOM_IN);
} catch (Exception ex) {
}
};
};
t.start();
}
if (v == ZoomOutButton) {
Thread t = new Thread() {
public void run() {
try {
CameraManagerScreen.ActiveCam
.goPTZ(CameraType.PTZ_ZOOM_OUT);
} catch (Exception ex) {
}
};
};
t.start();
}
}
}