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

Hello,

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) {
  2.  
  3.         super.onCreate(savedInstanceState);
  4.  
  5.         setContentView(R.layout.main);
Parsed in 0.030 seconds, using GeSHi 1.0.8.4


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

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

Top

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"
method.
Another way is to add
Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. android:configChanges="keyboardHidden|orientation"
Parsed in 0.000 seconds, using GeSHi 1.0.8.4
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.


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

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: Google [Bot] and 17 guests