Android: Remembering users previous tab selection

This is something I built into v2.0 of Pace Calculator, since often users would be only runners, cyclists or swimmers, and once they select a particular tab, they want the app to start-up in that tab every time. It uses the basic SharedPreferences object, all within the main activity that controls the ActionBarActivity tabs.

First, in MainActivity, set up the following variables

Integer tabPref;
SharedPreferences prefs;

In the onCreate method instantiate the variables, defaulting to 0 if the app has never been used before

prefs = getPreferences(Context.MODE_PRIVATE);
tabPref = prefs.getInt("tabPref", 0);

You need to make sure that when each tab is selected, the preference is also set, and editor.apply() called

		.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
			public void onPageSelected(int position) {
				SharedPreferences.Editor editor = prefs.edit().putInt(
						"tabPref", position);

Finally, at the end of OnCreate, you need to make sure that the tab determined in the preferences is selected with

mViewPager.setCurrentItem(tabPref, false);

That’s it!

Plantar fasciitis…

…is a right pain in the arse. Probably caused by running hard (Edinburgh 1/2 Marathon with Sandy Cleland) on shoes that were past it, then not resting up. Last week was a big running week for me, about 60km, and I’m now hobbling about. Remedies include massaging with Tiger Balm (homeopathy I guess, but it smells great) and rolling a frozen Sigg bottle on the floor with knackered foot. Hope it’s OK by tomorrow, hill reps on the bike. Wikipedia Plantar fasciitis >>>

Pace Calculator updated

Today I updated the first Android App I ever built (released December 2010!) Pace Calculator has been updated to include speed calculations for cyclists and pace per 100m for swimmers. Both run and bike tabs include metric (km) or imperial (mile) options. It’s been a useful exercise using action-bars, styles and swipe tabs, all new standards since I built the original app. APPS >>>

Further fun with WordPress

So, since this is my first play with WordPress, I’ve been applying a load of different ‘themes’ to the site, but always keep coming back to Formation. The others look good on screen preview, but these previews don’t seem to capture the same font sizes or page positioning. For now, Formation seems the business…

Forest run

Thetford (Norfolk) is fabulous. Well, the forest is anyway. A morning run on trail and track, in the sun, lifts the spirits, but tires the legs – 19km! Amazed to hear Cuckoo calling near the range (juvenile bird? I thought all adults were back in Africa, or maybe just leaving) and glad to see and hear Woodlark in the clear-fell areas north of Mayday Farm [Yes, these are now in BirdTrack].

Pace Calculator

Pace Calculator – a tool for runners, cyclists and swimmers to calculate pace or speed from time and distance. A three way algorithm allows any two elements to be entered to calculate the 3rd. Really useful for trying to predict future events! [or it is for me at least…] The screen to the left is an imminent release/update, but the current version can be found at link below.

Google Play Store >>>