Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Layout restarts after device's rotation [duplicate]

I did a simple application with 2 buttons (start and exit) and an empty TextView. If i push the start button, a TextView will be update. My problem is that if i rotate the device, my layout will restart (if start was pushed, the TextView will become empty again. Why?

like image 771
As As Avatar asked Nov 06 '13 15:11

As As


2 Answers

It because activity recreate after screen rotate. Simple fix is adding android:id to your TextView at xml.

like image 158
vmtrue Avatar answered Sep 20 '22 19:09

vmtrue


Android automatically destroys the activity and recreates it adapting it to the new orientation of the screen when the device is rotated.

like image 38
Niraj Adhikari Avatar answered Sep 19 '22 19:09

Niraj Adhikari