I’m new to Android app programming and started to read a book, but it just said write this to do this.
1) I want to know what each line of code actually means and does… So could someone explain the most common bits of code, what they do for someone completely new to Android (and programming in general) programming.
2) Could you also explain what each line of the following starter code means and where I edit?
package com.Vibris;
import android.app.Activity;
import android.os.Bundle;
public class VibrisActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
}
3) I know it’s a stupid question but the book confused me so much… Could someone explain what activities are and what they do and how they act? How do activities make up the app? Do you have to start with a particular activity?
4) What is the BEST way to start with Android development… Because (for me) a book really isn’t the way to go!
1) No can do. There is no such thing as ‘common code’. Figure out what you want to do, and then figure out how to.
2) It is just a normal Java class. The class extends Activity, to show the user some stuff. The
super.onCreate(..)should always be called. ThesetContentViewgrabs an xml file and inflates it so there is actually something to see on the screen. The editing then happens below thesetContentView, and ofcourse normal Java functions can be added.3) An Activity is the basic building block in Android. If you only need one screen, you’ll only need one Activity. In a phone app there could be an activity for dialing, one for showing contacts, etc.
4) Just try something! The best way to learn is “How can I do x”, and then figure out how to. There is plenty of documentation and there are many examples that can help you out. Start with small steps. (Like, “How can I show the menu?” or “How can I make a button do something?”)