Android Learning Notes 1 Start-up

Eventually I came to start Android dev, just can’t step over this area. It’s no doubt that Android users are more than iOS users, So my curiosity drivers me to  learn something about that.

Android Studio

I use to learn some Android dev, and that was in 2011, I read an atrocious pirated book which contains tons of ridiculous translations, it misguided me a lot and I just gave up after 3 days. I shouldn’t be so  scathing, it told me that Eclipse is the leading IDE to work out Android dev anyway.

This time I came back to learn it, I found a new IDE base on IntelliJ called “Android Studio” was on beta, That’s a better choice. Master BAI used to share some excellent things, JetBrains tools are some of those.

Advice from Master BAI: Try Android Studio on a bigger screen, you’ll find a new world.
I prefer to use original things, like FlashBuilder to Flash Dev, like Xcode to iOS Dev, like Nexus 5 to Android devices. Because their creators who are all huge, powerful strongholds. And they have abilities to produce some well-designed, graceful, efficient, robust products regardless of the cost.

I believe that nothing could be totally free, every single good comes with a “FREE” tag is another step for larger strategy. No-purchase, No good services.

Install and create a emulator

![](屏幕快照 2014-11-18 上午10.49.46.png)

The first sight to Android Studio is same to IntelliJ, WTF are those buttons, so many tags, labels, cascading  menus, drop-down menus, like making cakes with a plane dashboard. I just follow Ben’s (TH teacher, nice guy.) steps, and click that little robot with down-arrow.

![](屏幕快照 2014-11-18 上午10.59.38.png)

Choose the Android API version you need, for basic phone app, all you need are those two thing in the figure.

  • SDK Platform is the basic part, everything bases on it.
  • ARM EABI v7a System Image is the package you would need when you need to create a new emulator.
    ![](屏幕快照 2014-11-18 上午11.38.42.png)

Then click the AVD Manager button, it brings you to Android Virtual Devices Manager View, regarding to the evolution of AS, all the popup-windows might have different style and layout, just find out the options you need. The whole create steps are pretty simple, so I won’t post pics here.

Slow Emulator!

I found a blog here, the author listed 8 points to speed up emulator, the reason for such a low performance is:

The main reason is because it is emulating the ARM CPU & GPU, unlike the iOS Simulator, which runs x86 code instead of the ARM code that runs on the actual hardware. This means the iOS Simulator is typically faster than actual hardware, and the Android Emulator is slower than actual hardware.
The tips I can try are , #4 and #8, still don’t get a significant improvement. So if you have a actual device like me, use it instead of emulator is the best choice.

Don’t create new class under packages tag selected

![](屏幕快照 2014-11-18 下午1.29.33.png)

Because this is the view for files which are generated by AS, if you do that, you’ll get a warning like this:

![](屏幕快照 2014-11-18 下午1.31.04.png)

Remember switch tab to ‘project’ when you want to create new class.

Add listener to a button

The last time I did GUI program with java was in 2006, with java AWT and Swing framework, and my basics of interactive handling are from that too. Compare to that, Android version is quite easy to understand:

showFactButton.setOnClickListener(new View.OnClickListener() {
    public void onClick(View view) {
        //Things you wanna do.

In this style, a inner class was presented more like a block, handle the event at where you declare it makes feel so clear.

Useful Shortcuts

Find Class: (Mac) CMD+O, (Windows) CTRL+N

Find File: (Mac) CMD+SHFT+O, (Windows) CTRL+SHFT+N

Refactor/Rename: SHFT+F6

Quick Fix (including string resource refactor): ALT+ENTER

Go to Class Definition: (Mac) CMD+B, (Windows) CTRL+B

Run: (Mac) CTRL+R, (Windows) SHFT+F10

Debug: (Mac) CTRL+D, (Windows) SHFT+F9

Make a Toast

Toast is like a alert which can give you a popup message from the bottom of the screen.

Toast.makeText(this,"Here I AM!",Toast.LENGTH_LONG).show();

Hahahahahaha, it made me LOL, even the official doc represent it as:

“What a Terrible Failure: Report an exception that should never happen.”
I still think it’s just WHAT THE FUCK, and this makes me start to love coding with Android.