Is this the first run?
Ever wanted to have a different flow of actions on the second or third run of your app? I had that many times, in almost every project that I haver worked on. So here is a little snippet, that you can use to store, and check the fact, if this is the first run of your app. You can modify it easily, to suit your needs.
The easiest way to do this, is to use SharedPreferences. It can be slow, if you store a lot of data in it, so don't treat it like a database, or a file. Please note that it won't be deleted, when you update a program.
- /**
- * get if this is the first run
- *
- * @return returns true, if this is the first run
- */
- public boolean getFirstRun() {
- return mPrefs.getBoolean("firstRun", true);
- }
- /**
- * store the first run
- */
- public void setRunned() {
- SharedPreferences.Editor edit = mPrefs.edit();
- edit.putBoolean("firstRun", false);
- edit.commit();
- }
- SharedPreferences mPrefs;
- /**
- * setting up preferences storage
- */
- public void firstRunPreferences() {
- mPrefs = mContext.getSharedPreferences("myAppPrefs", 0); //0 = mode private. only this app can read these preferences
- }
Just put the firstRunPreferences() in your onCreate, put a big if(getFirstRun()){} where you need it (for example: before warning screen), and inside that, put setRunned(); .
New tutorials from Helloandroid
Recent Apps
Android on Twitter
-
@Idevicegazette (iDevice Gazette)
GSM-to-Skype bridge lets you lose those roaming fees http://bit.ly/lbRJeh #android
11 years 45 weeks ago -
@tommy_banane (tom b.)
RT @AndroidFavorite: #Android New Desktop Android Market Is Live, Adds Several New Features http://zorr0.nl/lFwXNz
11 years 45 weeks ago -
@dwilliams5 (Dennis Williams)
just completed a runtastic run of 3.02 km in 40 min 11 s with #runtastic #Android App: http://tinyurl.com/5tvrpe3
11 years 45 weeks ago -
@S_Pinz (Spinz!)
RT @Androidheadline: Out of box #LG Optimus 3D got Quadrant 2420 score. Thanks @blink_c #io2011 #android http://twitpic.com/4whkdz
11 years 45 weeks ago -
@tayaitapps (Taya IT)
Next Google TV Looks A Lot Like Android http://t.co/dvlTim3 via @alleyinsider #google #apple #android #tv #honeycomb
11 years 45 weeks ago
Poll
Useful resources
Android Development Projects
- iOS/Android Developer to take older Games and bring them Current
- Android apps developer - need to finish urgent.
- Buliding MobileApp For onlie order
- looking for android APP developers
- Create an ecommerce app
- text-to voice for smartphones IOS - GOOGLE - HARMONY - AND ALEXA
- Optimize Images on App
- Create small feature with drag-drop text for Android
- Scouting for advanced website and Mobile apps developers. Potential Long-term contract.
- BLACK SCREEN