0

Hey guys, i am making an android application where i want to show a dialog box about legal agreement everytime the application starts, i have a public method showalert(<>); which shows an alertdialog by building a dialog with alertbuilder. I added a call to showalert() method on the onCreate() method of the main activity to show it, but whenever the user rotates the screen, he gets the dialog everytime. The activity restarts itself when the phone is rotated. I tried adding android:configChanges="keyboardHidden|orientation" to my manifest but that doesnt help on this case. Also can i know how to register a new application class on manifest file. I am trying to create an application class and put the code to show dialog on the new class's oncreate method. But i am not being able to load the class when the app starts.

I also checked Activity restart on rotation Android but i dont seem to get a thing. I am pretty much a newbie to android programming, could someone simplify that for me?

Any help would be appreciated. :)

Community
  • 1
  • 1
KSubedi
  • 443
  • 1
  • 7
  • 17

2 Answers2

1

you could maybe look at the onRetainNonConfigurationInstance() activity method, which is called just before destroying and re-creating the activity on screen orientation change.

it allows you to retain an object that could for instance contain a test variable to know if your legal thing was already shown or not.. example :

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    final String test = (String) getLastNonConfigurationInstance();
    if (!("textAlreadyShown").equals(test)) {
        //here : show your dialog
    }
}

@Override
public String onRetainNonConfigurationInstance() {
    return "textAlreadyShown";
}   
darma
  • 4,687
  • 1
  • 24
  • 25
  • ok i partially got what you said, like could you give me an example code which actually saves a variable boolean before the screen changes, and how to get that variable after its changed. Pre thanks from my side :) – KSubedi Mar 09 '11 at 02:43
  • AWESOME! THANKS A LOT! Exactly what i have been looking for days! :) – KSubedi Mar 09 '11 at 02:46
  • Tested and tried, works :) for a second i thought that it was messed up again, but it was cuz i tried to pass boolean, works with string. can i know why it doesnt work when i try to pass a boolean value instead of string? – KSubedi Mar 09 '11 at 03:01
  • And sorry that i cant vote up as i dont have 15 reputation :) – KSubedi Mar 09 '11 at 03:21
0

Set the main activity to an activity that just shows the legal notice, when it is accepted/cleared, show a second activity ( which is currently the main activity )?

Dre
  • 4,298
  • 30
  • 39
  • Thanks, but i found a simpler solution, this method needs changing a bit more on my class files. I am plannning to use this on my next app. :D – KSubedi Mar 09 '11 at 03:07