Android: What does “Volatile” mean?

At work, I’m currently working on a very large project, and a lot of it was previously written by some very experienced programmers, far beyond my level of skill. When I read through it, I often come across weird things I’ve never seen before (a lot of which gives me the content to post here!) One of these I cam across recently was this word:

volatile

Its a strange prefix to a variable name, and the first few times I looked it up, I was not able to find a clear or concise answer. When I try to compile it into simple programs, it never yielded any visible differences. I have found this article from Javamex which put together a rather simple table and explanation of what it actually does.

Essentially, volatile is used to indicate that a variable’s value will be modified by different threads.

Briefly, I can tell you it is related to threads and synchronization, so if your programs don’t have a lot of multi thread functionality, this keyword *probably doesn’t affect you. Check out the article here and feel free to toss in any comments to shed light some more light for our readers!

-Kevin Grant

Texas dialR update

We’ve added three new stickers to Texas dialR!

See the new stickers on the dialR Facebook Page and get the update in the marketplace.

Android: Getting screen pixel size and dimensions

In one of our programs, I hackishly figured out how to get screen size based off of measuring a view in the onDraw() method and only doing it the first onDraw, and blah yada blah etc. This was terrible and I knew it from the beginning, but it works, so whatever. However, I have run into the same problem into a different project and that method won’t work here, so I researched it again. Low and behold, it was much easier that I ever thought (just like everything else).

DisplayMetrics metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics);

and now you can access everything you want through this “metrics” variable. Found this right on the android site under Display Metrics

-Kevin Grant

Mobile AP 3.0 teaser…

-Kevin Grant

Word Clock!

Just a quick update, we have released our first Chrome Web App! If you use Google Chrome, give the Word Clock a try! The direct link below.

Chrome Web Store: Word Clock

For those of you not using Google Chrome, you can see it in action at the link below. Internet Explorer users will not get to see the cool glow and smooth animations that Firefox, Safari, and Chrome users get to see because IE8 does not support CSS3 opacity (supposedly IE9 will support it). Instead, IE users currently will see a half-ass animated bar at the top of the page (which I put there to prove that it’s “working”). The clock still changes at the right time, but it won’t look as cool in IE.

Word Clock in action!

Keep an eye out because this will be coming to Android as well!

Android: Ain’t no Callerback grl… (Callback functions in Android)

When I learned about callback functions in Android, it literally created a whole new world of possibilities of what I could do withing my apps. For so long I had used callback functions without even knowing it! An example of a callback function we all already use is with buttons and the onClickListener(). Usually when you create a button, you register a listener, and then you put code into it, like so:

Button btn = (Button) findViewById(yada_yada_yada);
btn.setOnclickListener(new OnClickListener(){
	@Override
	public void onClick(View v){
		// do something
	}
});

Basically, whenever you press a button, it sends a callback to this listener you set, and your program can do whatever you want in here. What we want to do now is replicate this sort of callback, but not for a button press. We want to replicate this for ANYTHING! In the example code I provide, we can now do things like this:

rst = new RandomSenderThingy();
rst.setRandomThingyListener(new RandomSenderThingyListener(){
	@Override
	public void onBoolThingChanged(boolean changed) {
		Log.d("DEBUG","Callback Received! It is: " + changed);
	}
});

The example code makes use of a few various techniques to get the point across, but I’ve clearly commented the parts that you will need to inject into your own code to get this functionality. Good luck and post any questions or comments in the comments section!

Download the source code here

-Kevin Grant

Android: Random Numbers and things!

Quick reference post. Partially for you, mainly for me, since I always forget how to do random numbers.

Random generator = new Random();

int x = generator.nextInt(100);
boolean flag = generator.nextBoolean();

Works great in loops! The nextInt(int) function will give you the next random integer between 0 and 99 (not 100!). You can of course set that number to anything, 3, 5, 800, etc. You can even try nextDouble(double) if you’re feeling dangerous…

Just make sure you import

import java.util.Random;

And you’re good to go!

-Kevin Grant

Learn how to code!

LifeHacker recently did a series on the basics of programming. In their articles, they are using JavaScript which is very easy to use and you don’t need to download any SDK or compiler. Just open up your favorite text editor and do your code, then save and view the results in your favorite web browser. Here are the links in case you missed it:

Part 1: Variables and Datatypes
Part 2: Working with Variables
Part 3: Arrays and Logic Statements
Part 4: Understanding Functions and Making a Guessing Game
Part 5: Learn to Code Epilogue: Best Practices and Additional Resources

Android Market: Do application upgrades count as new downloads?

I usually do daily monitoring of the inphamous marketplace so I can properly see which apps need the most lovin’. I was curious how and if those upgrades are counted from previous users. After a little searching, I found this nice gem from stack overflow.

1 person installing your app = 1 download. Upgrades do not add to this.

-mbaird

This confirmed what I was thinking, and if you think logically about your “active installs” numbers, then it makes sense that users should not be double counted, as this would provide some very biased results.

Check out the link to see the source question.

-Kevin Grant

Android: Debug certificate expired

Have you received this error?

Error generating final archive: Debug Certificate expired on 2/9/2011 11:55 PM

I just got it today! The fix is quite simple, just locate your debug.keystore file, delete it, and and then select “clean all projects” in eclipse. I followed this brief tutorial from a guy over at “The Java Dude”.

Check out his tutorial here

-Kevin Grant