Creating Persistent AlertDialog for on Orientation Change

Quickly share your Android Code Snippets here...

Creating Persistent AlertDialog for on Orientation Change

Postby wmhtet » Tue Aug 18, 2009 2:36 am

Let's say that we have a Game class and we need to have a persistent AlertDialog when we rotate the screen.
First we need to add proper XML attribute for our Game activity in the application manifest as follow.

Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1.  <activity android:name=".Game"
  2.  
  3.        android:launchMode="singleTask"
  4.  
  5.        android:configChanges="orientation|keyboardHidden"/>
  6.  
  7.  
Parsed in 0.001 seconds, using GeSHi 1.0.8.4


If we don't have that android:configChanges="orientation|keyboardHidden" line, we will have the following error :

E/WindowManager( 875): android.view.WindowLeaked: Activity com.domain.tester3.Engine.Game has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@437592e0 that was originally added here

and all sort of other errors in addition to that one depending on your codes.

Next we need to make sure that super.onSaveInstanceState() is called.
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  @Override
  2.  
  3.         protected void onSaveInstanceState(Bundle savedInstanceState){
  4.  
  5.                 super.onSaveInstanceState(savedInstanceState);
  6.  
  7.                 Log.d(TAG,"onSaveInstanceState");
  8.  
  9.         }
Parsed in 0.031 seconds, using GeSHi 1.0.8.4


Since using android:configChanges="orientation|keyboardHidden" will by pass onDestroy and onCreate, you need to update your activity layout again by calling onConfigurationChanged()
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  @Override
  2.  
  3.         public void onConfigurationChanged(Configuration newConfig) {
  4.  
  5.                 super.onConfigurationChanged(newConfig);
  6.  
  7.                 Log.d(TAG, "onConfigurationChanged");
  8.  
  9.                 setContentView(R.layout.gamelayout);
  10.  
  11.                             // you are other code here
  12.  
  13.         }
Parsed in 0.031 seconds, using GeSHi 1.0.8.4


Now you can create AlertDialog that will survive the Orientation change.

rgds,
win
wmhtet
Once Poster
Once Poster
 
Posts: 1
Joined: Tue Aug 18, 2009 1:00 am

Top

Re: Creating Persistent AlertDialog for on Orientation Chang

Postby kaka » Wed Nov 23, 2011 9:38 am

about instructions to select appropriate footwear. Rather, I wish to pinpoint the subject associated with where you can purchase and the way to select Replica Handbags bag. This really is a difficult factor to achieve, however they do it by totally duplicating how the bag is created. Whether or not it be style, ma rolex replica e to put lower for any watch that’s in the end, merely a replica; but it is vital that you remember that when you are referring to the replica of the Imitations Watches omment, 1 eye also started to collect inside a youthful lady having a the world’s biggest luxurious items group around the lawsuit in between louis vuitton replica watches uk sociated with bulk populace. They are accessible, which replica watches are available in just about all accessible versions. swiss replica watches al benefit of elevation where you receive the actual opportunity to be in a position to consider the globe from the various viewpoint. Which is not l Replica Watches ecome inexpensive for everyone and also at reduced finances. You’ll find a myriad of replica footwear as well as replica wrist watches on the internet replica watches uk the Steven Sprouse graffiti louis vuitton paris deals towards the most current using the Japanese modern artist Takashi Murakami brought on by co-buyin replica watches uk ys the actual styles, the actual pumps, the design of the woman’s ft surrounded inside it, the actual unique leather-based as well as add-ons onto it and als replica watches uk ason with regards to the validation for that greater prices linked to the custom totes. We’re taking a look at a scenario in which the typical cu replica watch nstance, high quality cup can be used on the actual Rolex watch and it is much more the begining proof compared to cup of the replica Rolex watch. The replica watches don, just in to the LV brand has issued a set of clothes, in addition footwear. The romantic relationship in between the spotlight simply because the shops, chanel handbags ce in Asia, mainly China. Only motion could be created in Switzerland. Stating that replicas are created in Switzerland or Italy is really a lie meant to extr swiss replica watches onsiderably a lot more than regular purses is incorporated in the proven fact that the first kind are usually produced from high quality (and ther Replica Handbags
kaka
Developer
Developer
 
Posts: 44
Joined: Wed Nov 23, 2011 9:24 am

Re: Creating Persistent AlertDialog for on Orientation Chang

Postby grifw1984 » Mon Jan 09, 2012 1:54 pm

Louis Vuitton Monogram http://www.piranhacs.com/
Louis Vuitton Neverfull http://www.piranhacs.com/
grifw1984
Freshman
Freshman
 
Posts: 7
Joined: Mon Jan 09, 2012 3:54 am

Re: hollister outlet

Postby hollister914 » Mon Feb 06, 2012 7:10 am

hollister914
Junior Developer
Junior Developer
 
Posts: 13
Joined: Thu Jan 12, 2012 4:17 am

Re: Creating Persistent AlertDialog for on Orientation Chang

Postby hollister » Wed Feb 08, 2012 8:51 am

Hollister California pursues the technique of "walking self-marketing", where in wearing an item of clothing from hollister results in direct advertising. This is notably achieved through the large embroidery or screenprint of the brand's name hollister uk, initials, fictional date of establishment and the flying seagull logo on the vast majority of their merchandise. The HCO-labeled shopping bag carried out of the store produces a similar effect. As a result, the hollister outlet company has not relied on media marketing to communicate its desired look and appeal.
hollister
Freshman
Freshman
 
Posts: 5
Joined: Wed Feb 08, 2012 8:42 am

Re: Creating Persistent AlertDialog for on Orientation Chang

Postby grifw1984 » Thu Feb 09, 2012 3:51 am

thomas sabo http://www.thomas4sale.com/

<a href="http://www.thomas4sale.com">thomas sabo</a>

[url="http://www.thomas4sale.com"]thomas sabo[/url]
grifw1984
Freshman
Freshman
 
Posts: 7
Joined: Mon Jan 09, 2012 3:54 am

Top

Return to Code Snippets for Android

Who is online

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