Loosing Info when screen is rotated

Put your problem here if it does not fit any of the other categories.

Loosing Info when screen is rotated

Postby bob3695 » Fri Apr 10, 2009 5:59 pm


I'm writing my first Android app. I am using zxing and pulling info from a website about the product and everything is working fine...except when the phone is rotated it looses the info on the screen. All i have on the screen is a TextView and a button. The button starts Barcode Scanner which when scanned it goes to the internet and pulls in the info about the product. It shows it in the TextView just fine but if i rotate my phone the text disapears! My guess would be in the onCreate method? Here is the part I would THINK the problem would be:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. public void onCreate(Bundle savedInstanceState) {
  3.         super.onCreate(savedInstanceState);
  5.         setContentView(R.layout.main);
Parsed in 0.010 seconds, using GeSHi

If you guys think its somewhere else i will be more then happy to show you the code there.

Posts: 3
Joined: Fri Apr 10, 2009 5:54 pm


Postby padde » Sat Apr 11, 2009 1:48 am

When you rotate the device the activity get restarted to take account of the orientation change of the display.
There are several ways to fix your problem or change that behaviour.
I would suggest you implement "onSaveInstanceState" method and save all user data and so on.
When the activity restarts you can read in the saved state in the "onCreate" method or in "onRestoreInstanceState"
Another way is to add
Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. android:configChanges="keyboardHidden|orientation"
Parsed in 0.000 seconds, using GeSHi
for your activity in the AndroidManifest.xml and implement "onConfigurationChanged" method. This allows you to take care
of orientation changes for yourself and stops restarting your activity on orientation change.

Master Developer
Master Developer
Posts: 443
Joined: Wed Apr 08, 2009 4:52 pm


Return to Other Coding-Problems

Who is online

Users browsing this forum: No registered users and 8 guests