I’ve been developing an Android App and I have encountered a small problem when putting my phone horizontally.
At the moment I have two views: The main one (main.xml) and a login view (login.xml). When I turn my phone while being in the login.xml view, it returns me to the main.xml view. The same thing happens if the phone is in horizontal position + login.xml and I turn it again (goes back to main.xml).
It sees that the “OnCreate” is executed each time, here is the code for the app:
public class AppActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ImageButton bout= null;
bout = (ImageButton)findViewById(R.id.imageButton1);
bout.setOnClickListener(boutlisten);
}
private OnClickListener boutlisten = new OnClickListener(){
public void onClick(View v) {
setContentView(R.layout.login);
}
};
}
Thanks in advance!
Create new Activity which have
setContentView(R.layout.login);and start Activity.Like,
Addendum: This is the code to launch the activity declared above. One should also declare the activity in the manifest file