Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Flobbster
Feb 17, 2005

"Cadet Kirk, after the way you cheated on the Kobayashi Maru test I oughta punch you in tha face!"
In fairness, you can go straight to the source and blame Java for that one, since they didn't decide that isEmpty() might be useful for strings until 1.6 :wtc:

The current state of fragmentation on Android is ridiculous though. I use Android in my data structures course and I hate that I still have to use 2.2 as my baseline for all the projects because that's what most of my students still have. And it really pisses me off that we bought a batch of Samsung 7" Galaxy Tabs last year for classroom use and we can't even upgrade those (officially) past 2.3.

The only reason I can tolerate programming in Java anymore is because of Android, and I'm excited about when they finally get around to adding lambdas (maybe in Java 8?). But what are the chances I'd be able to use those on Android if I can't upgrade it? Not much, unless their implementation is all compile-time transformations and doesn't require JVM changes.

Adbot
ADBOT LOVES YOU

Flobbster
Feb 17, 2005

"Cadet Kirk, after the way you cheated on the Kobayashi Maru test I oughta punch you in tha face!"
So I've been teaching an intro CS class using Android for the past year, and this semester I'm finally upgrading all my assignments' target SDKs from 2.2 to 4.0, while retaining as much compatibility as possible with other devices.

One change I'm making is having students to more with action bars. So, I've created a menu that has 5 items, set showAsAction="always" on all of them. Overrode onCreateOptionsMenu to inflate it in my activity. On a 4.0 emulator, they all show up like I'd expect, and clicking them does the right thing.

On a 2.2-2.3 emulator or device, the menu is loaded and appears properly when I click the Menu button, but clicking the items doesn't do anything. The menu doesn't even get dismissed. I tossed some logging statements in there, and onOptionsItemSelected is never being called. Even setting an onMenuItemClicked handler on the items themselves doesn't change anything.

Has anyone seen this kind of behavior before? I'm not sure what's going on, and Googling has been futile so far.

EDIT: I'm NOT using ActionBarSherlock or anything like that. Everything is standard Android APIs, and I'd rather not bring in third party libraries.

Flobbster fucked around with this message at 03:18 on Feb 21, 2013

Flobbster
Feb 17, 2005

"Cadet Kirk, after the way you cheated on the Kobayashi Maru test I oughta punch you in tha face!"
By "intro" I don't mean a first-semester CS course. It's Intro to Software Design and Data Structures, so they already have plenty of experience with the basics of Java and can move on to more advanced stuff.

We've developed some nice abstractions for them to use that get rid of a lot of the Android grunt-work, inspired by and stealing/improving ideas from frameworks like Roboguice, but I don't want to derail the thread talking about that -- unless people are interested :v: It works better than it might sound at first, though.

Flobbster
Feb 17, 2005

"Cadet Kirk, after the way you cheated on the Kobayashi Maru test I oughta punch you in tha face!"

Freakus posted:

I've been tasked with writing an android app when I have no experience with android. I was looking at google cloud messaging (gcm) and had a couple of clarifications related to the code of their example usage of gcm at:
http://developer.android.com/google/gcm/client.html

1) The example only checks GooglePlayServicesUtil.isGooglePlayServicesAvailable in onCreate. It seems like one would want to check it in onResume though.

Huh? From the sample:

code:
// You need to do the Play Services APK check here too.
@Override
protected void onResume() {
    super.onResume();
    checkPlayServices();
}
I can think of one use case where it's important to call it in onResume: If your activity checks for the existence of Play Services and doesn't find them, you can display a button that sends them to the Play Store to download it. When they return to your app, if it's been in the background this whole time, onCreate won't get called again, but onResume will. Then you can update the UI to let the user continue.

quote:

2) Presumably we need to check GooglePlayServicesUtil.isGooglePlayServicesAvailable in any activity we use them, not just the main activity.

Not every activity, just any that are an entry point into your application. If all your other activities are internal and only accessible starting from a main activity that checks for Play Services, you don't need to worry about doing it again there.

quote:

3) With the code given, it seems like the usage of registerInBackground may cause a race condition: what if you attempt to use gcm.send before the asynctask finishes? Is there something about android that will ensure this never happens in the sample code?

So make sure you don't call gcm.send before the task finishes. Break up your code so that you use the task's onPostExecute method as a "continuation" so that you only call it after you're sure it's ready.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply