first startup of app

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

first startup of app

Postby MagicMojo » Wed Feb 16, 2011 11:45 pm

So I was wondering about how to go about the installation and setup of an app. E.g. I want to make an SQL DB, but I only want to make it once. Maybe also start off by presenting the user with an intro screen. Do I just code this into onCreate of main activity? How does my app know this is the first launch? Do I create a data file and test that in my code, like so: if (datafile.usedBefore=false){showWelcomeScreen(); createDB();}
// else do the regular stuff:
GetInputFromScreen();
bool
TakeOverTheWorld=true;
String countryName; // in alphabetical order
OverThrowGovernment(countryName);
???
Okay, this is a silly example, but it's really only pseudocode, I'm new to both Android and Java, what did you expect? That it would compile on the first attempt? And you didn't think I'd give everything away, now, did you? This app is a full-proof path to world domination, man, but help me out here, and I promise I'll be good to you, when I've ascended to power;-D
MagicMojo
Junior Developer
Junior Developer
 
Posts: 10
Joined: Sat Nov 27, 2010 9:40 am

Top

Re: first startup of app

Postby Mardaneus » Thu Feb 17, 2011 8:25 am

The best way to display an intro/setup screen is to store a boolean variable in the shared preferences of your application (e.g. first_run or something similar, and default it to true). Then in your main activity you check whether this variable is true. If it is, you display the setup screen and set the variable to false.

To make databases I suggest to use the Android's built in SQLiteDatabaseHelper. It provides help for creating and upgrading your database only when needed (the system manages wheter the database must be created or upgraded, or nothing should happen).

Creating it only once in a setup activity can be error prone.
Mardaneus
Junior Developer
Junior Developer
 
Posts: 14
Joined: Mon Feb 14, 2011 10:30 am

Re: first startup of app

Postby strider2023 » Mon Feb 28, 2011 11:31 am

This code snippet was particularly useful to me when I started with android...

http://www.helloandroid.com/tutorials/first-run
strider2023
Senior Developer
Senior Developer
 
Posts: 126
Joined: Tue Mar 02, 2010 6:34 am
Location: Chennai, India

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: Google [Bot], Yahoo [Bot] and 13 guests