Launching a Dialog only the first time the app starts.

Basic Tutorials concerning: GUI, Views, Activites, XML, Layouts, Intents, ...

Launching a Dialog only the first time the app starts.

Postby emooney » Sat Feb 06, 2010 5:40 am

Upon opening the app for the first time, I want the user to be presented with a dialog asking them if they would like some data to be prefilled. After they select ok or cancel, it should never come up on any subsequent app starts.

How can I control that dialog to only show the very first time they start the app?

Thanks
Eric
emooney
Junior Developer
Junior Developer
 
Posts: 14
Joined: Tue Jan 26, 2010 11:03 pm

Top

Postby Keenora » Thu Feb 18, 2010 10:38 am

I think the easiest way is to use the Preferences and everytime, you start the onCreate of your Main Activity, you count the pref up. And in the onCreate you just check, if the pref is 0.
User avatar
Keenora
Freshman
Freshman
 
Posts: 5
Joined: Wed Feb 03, 2010 2:08 pm

Postby Boni2k » Thu Feb 18, 2010 2:21 pm

Keenora wrote:I think the easiest way is to use the Preferences and everytime, you start the onCreate of your Main Activity, you count the pref up. And in the onCreate you just check, if the pref is 0.

Yep, I did it this way, too.
Boni2k
Experienced Developer
Experienced Developer
 
Posts: 88
Joined: Sun Dec 20, 2009 9:46 pm

Postby emooney » Fri Feb 19, 2010 5:09 pm

sweet. thanks!
I'll give that a try.
emooney
Junior Developer
Junior Developer
 
Posts: 14
Joined: Tue Jan 26, 2010 11:03 pm

Postby TheChosen » Fri Feb 19, 2010 8:21 pm

It would be a nicer way to just add a boolean and initially it is false and the next time you read it you turn it into true. Once it is true, you don't show the dialog any more:

if (prefs.getBoolean("myVal", false)) {
// show dialog...
prefs.putBoolean("myVal", true);
}
TheChosen
Experienced Developer
Experienced Developer
 
Posts: 62
Joined: Tue Jan 06, 2009 7:18 pm
Location: Germany

Re: Launching a Dialog only the first time the app starts.

Postby benbeezy » Mon May 24, 2010 5:36 pm

Can someone please elaborate a little more in depth on this procedure? I'm facing a similar issue and could use a little more detailed guidance :)
benbeezy
Freshman
Freshman
 
Posts: 3
Joined: Mon May 24, 2010 5:34 pm

Top

Re: Launching a Dialog only the first time the app starts.

Postby blundell » Wed May 26, 2010 7:07 pm

Set a preference that the user cannot change and set it to true

when your app starts in onCreate check if that preference is true if it is do whatever you want to do then set it to false

Job done
User avatar
blundell
Master Developer
Master Developer
 
Posts: 1610
Joined: Tue Nov 18, 2008 12:58 pm
Location: UK

Top

Return to Novice Tutorials

Who is online

Users browsing this forum: No registered users and 8 guests