Avoid call to onCreate on config. change

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

Avoid call to onCreate on config. change

Postby devdattac » Wed Jun 23, 2010 1:42 pm

Hi All,

How can I avoid invocation of onCreate() method when I was switch from portrait mode to landscape mode or landscape to portrait. If it is not possible then how can I restore the state of my activity on configuration change ?

Please help me ASAP...

Thanx
devdattac
Junior Developer
Junior Developer
 
Posts: 13
Joined: Thu Jan 15, 2009 2:14 pm
Location: Pune

Top

Re: Avoid call to onCreate on config. change

Postby HaitiBoy » Wed Jun 23, 2010 6:14 pm

It is probably not possible to avoid onCreate() method, but
you can save your's application state by overriding onSaveInstanceState(Bundle outState) method
HaitiBoy
Freshman
Freshman
 
Posts: 6
Joined: Fri Jun 18, 2010 6:35 pm
Location: Houghton, Michigan

Re: Avoid call to onCreate on config. change

Postby devdattac » Thu Jun 24, 2010 5:24 am

Thanks for the reply HaitiBoy.......

When I switch from portrait to landscape onCreate() called only once but then if I switch from landscape to portrait onCreate() called twice . Is this a known issue ? What should I do ?
devdattac
Junior Developer
Junior Developer
 
Posts: 13
Joined: Thu Jan 15, 2009 2:14 pm
Location: Pune

Re: Avoid call to onCreate on config. change

Postby saranya » Fri Jun 25, 2010 8:02 am

<activity android:name=".MainActivity" android:label="@string/app_name" android:configChanges="orientation|keyboardHidden">
Use android:configchanges attribute to avoid restart of activity when screen orientation changes.

In MainActivity class use
public void onConfigurationChanged(Configuration newConfig) {
// Ignore orientation change not to restart activity
super.onConfigurationChanged(newConfig);
}
This solution will solve your problem.

Thanks,
Saran
saranya
Developer
Developer
 
Posts: 48
Joined: Wed Oct 22, 2008 8:06 am

Re: Avoid call to onCreate on config. change

Postby devdattac » Fri Jun 25, 2010 2:12 pm

Thanks for the reply saranya...... its working...
devdattac
Junior Developer
Junior Developer
 
Posts: 13
Joined: Thu Jan 15, 2009 2:14 pm
Location: Pune

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: No registered users and 13 guests