Just shy of a week past my poor old Nexus 5’s miraculous recovery (whence the screen was replaced) I’ve broken it again, and this time catastrophically.
Sigh. Why do bad things happen to good people, and also to me?
A friend’s husband contacted me about an android app, so I made him a quick one. It basically just grabs an image from his website and displays it. Every minute or so, it does this again.
Pretty boring, right? But maybe someone wants to load an image from the web. I know I did. Just recently, in fact1.
1. see above.
I’m going to do this in the easiest way I can think of. For anything more complicated, an NME extension would probably work well for this sort of thing!
After starting a new NME project in FlashDevelop, I created MainActivity.java in the project directory:
Man, I am having the hardest time naming these posts, but I promise that I’m not just typing random words next to each other.
I’ve uploaded the code for my demo from Cauê’s presentation; which you should be able to browse or checkout if you want to try it for yourself. There’s a description.txt file in there that should.. you know, describe some things.
Hopefully I didn’t break it between then and now! That would be embarassing, but let me know if that is the case and I’ll try to fix it and feel shame simultaneously.
In case you missed it, the code is here: http://svn.gigglingcorpse.com/examples/haxe java toast/
If you want to read more about the demo, I’ve talked about it in a few of my past posts:
Last time I discussed setting up a project to create java code, for android, from haxe. I left out some neat stuff because it was already pretty long. If you read it, you probably noticed.
For example, the program was called Haxe-Java Toast, which from the code presented is wildly inaccurate. Well, maybe not wildly, but you get the idea.
My goal was to do was create an android application with its interface defined by XML, and which called a function from the Android SDK (in this case triggered a Toast). What I pasted last time was a subset of the code in MyActivity.java.
There may end up being a lot of code here.
NME is a great solution for writing applications for the Android platform, but sometimes it’s nice to escape the confines of GameActivity.java. This is fairly easy to do, but unfortunately until now it meant writing Java.
Which is fine for some people, but given the option I’d avoid it. (For one thing, it’s lead me to using two separate editors simultaneously: FlashDevelop and Notepad++.)
The convenience of using NME, along with the power and freedom that comes from using Java for Android, without ever having to leave HaXe, is one of the benefits of HaXe’s upcoming Java target. And for me, it’s a pretty major one.
There are three main steps. The first is writing the code, and the other two are the two-stage compilation process. I imagine most of the stuff I discuss will end up being automated nicely, but for now this is how I went about it.
I made a simple SMS relay for my android (Andrew) last night. In case you want to do something similar, good news I’m about to explain its code!
Note: I used NME and notepad++ and flashdevelop and java, instead of NME and haXe, or Eclipse and Java. This might strike you as strange. It probably is strange, but it’s easier and more comfortable for me. The code shown will mostly be java and XML, which should match up nicely if you’re using Eclipse and Java, and you can take a look at Programming for android in Java but using NME if you’re using NME.